Is this code for structure OVERLAPPED correct ?
I simply cannot found in any include file this declaration
Public Structure OVERLAPPED
Public Internal As Long
Public InternalHigh As Long
Public offset As Long
Public OffsetHigh As Long
Public hEvent As Long
End Structure
Hi Zlatko,
This structure is quite interesting.
I came out with the following two examples.
Two definitions, depending on how you like it.
Once more, I'm impress by the beauty of o2, thank to Charles!
// KickSwitch -64 //-mem32 -32 -64 -run -dll (No Switch mean -mem32)
// KickEnd
// C++ typedef struct _OVERLAPPED {
// C++ ULONG_PTR Internal;
// C++ ULONG_PTR InternalHigh;
// C++ union {
// C++ struct {
// C++ DWORD Offset;
// C++ DWORD OffsetHigh;
// C++ } DUMMYSTRUCTNAME;
// C++ PVOID Pointer;
// C++ } DUMMYUNIONNAME;
// C++ HANDLE hEvent;
// C++ } OVERLAPPED, *LPOVERLAPPED;
struct OVERLAPPED{ // 32bit, 64bit
dword *internal // 4 bytes, 8 bytes (dword pointer)
dword *internalhigh // 4 bytes, 8 bytes (dword pointer)
union{ // 8 bytes, 8 bytes
struct{ // dummyStructName 8 bytes
dword offset // 4 bytes, 4 bytes (dword)
dword offsetHigh // 4 bytes, 4 bytes (dword)
}
void *pointer // 4 bytes, 8 bytes <- 4 bytes in 32bit but the 8 bytes union will pad it (void pointer)
} //
sys hevent // 4 bytes, 8 bytes (handle)
}
include once "D:\Dev\Oxygen\o2\inc\console.inc"
'_____________________________________________________________________________
SetConsoleTitle "overlapped structure"
long BitNess = sizeof(sys) * 8
printl
printl "in 32bit overlapped = 20 bytes"
printl "in 64bit overlapped = 32 bytes"
printl
printl "overlapped size = " sizeof(OVERLAPPED) " bytes"
printl "bitness = " BitNess "bit"
printl
overlapped ov
@ov.internal = 10
printl "ov.internal = " @ov.internal
@ov.internalhigh = 20
printl "ov.internalhigh = " @ov.internalhigh
@ov.pointer = 30
printl "ov.pointer = " @ov.pointer
ov.offset = 31
printl "ov.offset = " ov.offset
ov.offsetHigh = 32
printl "ov.offsetHigh = " ov.offsetHigh
ov.hevent = 40
printl "ov.hevent = " ov.hevent
printl
printl "any key to end"
waitkey
end
'_____________________________________________________________________________
'
// KickSwitch -64 //-mem32 -32 -64 -run -dll (No Switch mean -mem32)
// KickEnd
// C++ typedef struct _OVERLAPPED {
// C++ ULONG_PTR Internal;
// C++ ULONG_PTR InternalHigh;
// C++ union {
// C++ struct {
// C++ DWORD Offset;
// C++ DWORD OffsetHigh;
// C++ } DUMMYSTRUCTNAME;
// C++ PVOID Pointer;
// C++ } DUMMYUNIONNAME;
// C++ HANDLE hEvent;
// C++ } OVERLAPPED, *LPOVERLAPPED;
struct OVERLAPPED{ // 32bit, 64bit
sys internal // 4 bytes, 8 bytes (dword pointer)
sys internalhigh // 4 bytes, 8 bytes (dword pointer)
union{ // 8 bytes, 8 bytes
struct{ // dummyStructName 8 bytes
dword offset // 4 bytes, 4 bytes (dword)
dword offsetHigh // 4 bytes, 4 bytes (dword)
}
sys pointer // 4 bytes, 8 bytes <- 4 bytes in 32bit but the 8 bytes union will pad it (void pointer)
} //
sys hevent // 4 bytes, 8 bytes (handle)
}
include once "D:\Dev\Oxygen\o2\inc\console.inc"
'_____________________________________________________________________________
SetConsoleTitle "overlapped structure"
long BitNess = sizeof(sys) * 8
printl
printl "in 32bit overlapped = 20 bytes"
printl "in 64bit overlapped = 32 bytes"
printl
printl "overlapped size = " sizeof(OVERLAPPED) " bytes"
printl "bitness = " BitNess "bit"
printl
overlapped ov
ov.internal = 10
printl "ov.internal = " ov.internal
ov.internalhigh = 20
printl "ov.internalhigh = " ov.internalhigh
ov.pointer = 30
printl "ov.pointer = " ov.pointer
ov.offset = 31
printl "ov.offset = " ov.offset
ov.offsetHigh = 32
printl "ov.offsetHigh = " ov.offsetHigh
ov.hevent = 40
printl "ov.hevent = " ov.hevent
printl
printl "any key to end"
waitkey
end
'_____________________________________________________________________________
'
Also, if you prefer the simplified structure, I wrote a test to see if all was perfecto mundo in 32 and 64 bit.
So far, so good...
// KickSwitch -64 //-mem32 -32 -64 -run -dll (No Switch mean -mem32)
// KickEnd
uses Console
uses MinWin
uses Dialogs
%CREATE_NEW 1
%CREATE_ALWAYS 2
%OPEN_EXISTING 3
%OPEN_ALWAYS 4
%TRUNCATE_EXISTING 5
%FILE_FLAG_OVERLAPPED 0x40000000
%INFINITE 0xFFFFFFFF
%FORMAT_MESSAGE_FROM_SYSTEM 0X1000
%FORMAT_MESSAGE_ALLOCATE_BUFFER 0X100
%ERROR_IO_PENDING 997
%FILE_BEGIN 0
%FILE_CURRENT 1
%FILE_END 2
'struct OVERLAPPED{ // 32bit, 64bit
' sys internal // 4 bytes, 8 bytes (dword pointer)
' sys internalhigh // 4 bytes, 8 bytes (dword pointer)
' union{ // 8 bytes, 8 bytes
' struct{ // dummyStructName 8 bytes
' dword offset // 4 bytes, 4 bytes (dword)
' dword offsetHigh // 4 bytes, 4 bytes (dword)
' }
' sys pointer // 4 bytes, 8 bytes <- 4 bytes in 32bit but the 8 bytes union will pad it (void pointer)
' } //
' sys hevent // 4 bytes, 8 bytes (handle)
'}
struct OVERLAPPED{ 'simplified
sys Internal
sys InternalHigh
dword Offset
dword OffsetHigh
sys hEvent
}
'_____________________________________________________________________________
SetConsoleTitle "overlapped structure"
long BitNess = sizeof(sys) * 8
printl "bitness = " BitNess "bit"
printl
dword WrittenCount = 0
string sFileName = "overlapped.txt"
string sFileData = "filedata"
overlapped overlapp
overlapp.offset = 8
'overlapp.hevent = CreateEvent(BYVAL 0, %FALSE, %FALSE, "") '"someEvent")
sys hFile = CreateFile(sFileName, %GENERIC_READ OR %GENERIC_WRITE, %FILE_SHARE_READ, 0,
%OPEN_ALWAYS, %FILE_ATTRIBUTE_NORMAL | %FILE_FLAG_OVERLAPPED, 0)
If hFile <> %INVALID_HANDLE_VALUE
if WriteFile(hFile, sFileData, LEN(sFileData), @WrittenCount, @overlapp) = 0 'nzok
GetOverlappedResult(hFile, @overlapp, @WrittenCount, %true) 'nzok
endif
CloseHandle(hFile)
printl "WrittenCount " str(WrittenCount)
end if
'WaitForSingleObject(overlapp.hevent, %INFINITE) '2000) '%INFINITE)
printl
printl "check the file " chr(34) sFileName chr(34)
printl
printl "any key to end"
waitkey
end
'_____________________________________________________________________________
'
hi Piere
i have some mess with this using CreateProcess example
but now work
thanks