You don't need to pass a pointer to an overlapped structure and if you are finding the examples too complicated don't use it. WinAPI can be complicated in general and it is often easier to accomplish what you need directly in .Net and avoid WinAPI altogehter.
To answer your question the structure would be defined as:
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
However, System.Threading has two classes Overlapped
and NativeOverlapped
meant to make life easier. Overlapped
is a .Net class which you can pack
into a NativeOverlapped
. The structure allows you to set a call back to be fired:
In C# you would define it like this:
Overlapped overlapped = new Overlapped();
NativeOverlapped* nativeOverlapped = overlapped.Pack(
DeviceWriteControlIOCompletionCallback,
null);
Note I said in C#, that's because Net. doesn't support the return type in VB because it is unsafe code:
Visual Basic does not support APIs that consume or return unsafe types.
So if you are really looking to do Overlapped IO, it might be a lot easier for you code your overlapped methods in a C# class library, which you can then reference in and call in your VB application.
From All API:
· lpOverlapped Points to an OVERLAPPED structure. This structure is
required if hFile was opened with FILE_FLAG_OVERLAPPED. If hFile was
opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not
be NULL. It must point to a valid OVERLAPPED structure. If hFile was
opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the
function can incorrectly report that the write operation is complete.
If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not
NULL, the write operation starts at the offset specified in the
OVERLAPPED structure and WriteFile may return before the write
operation has been completed. In this case, WriteFile returns FALSE
and the GetLastError function returns ERROR_IO_PENDING. This allows
the calling process to continue processing while the write operation
is being completed. The event specified in the OVERLAPPED structure is
set to the signaled state upon completion of the write operation. If
hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is
NULL, the write operation starts at the current file position and
WriteFile does not return until the operation has been completed. If
hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not
NULL, the write operation starts at the offset specified in the
OVERLAPPED structure and WriteFile does not return until the write
operation has been completed.