
Passing a NULL value to API parameters that take UDTs
Hi all,
In some MSDN Library API documentation, I find that under certain
circumstances, Windows API functions expect null values to parameters that take
UDTs (or, to C/C++ programmers, structs). How would I go about doing this in
VB?
For example, the big problem I'm having is with trying to use the ReadFile
function, which I have to use because of the nature of the file I'm trying to
read.
The ReadFile VB API declaration is
Public Declare Function ReadFile Lib "kernel32" Alias "ReadFile" (ByVal hFile
As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long,
lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long
Keep in mind that last parameter; it'll be useful. A snippet of C++ code that
will use ReadFile to read in 255 bytes from a file is:
ReadFile(hStdin, chBuffer, 255, &cRead, NULL)
hStdin is the file handle, chBuffer is the character buffer, 255 is the amount
of characters to read in, cRead is the variable to store the amount of
characters read in, and NULL is the parameter that is, frankly, pissing me off.
The last parameter expects a pointer to the OVERLAPPED struct...but C++ passes
it a NULL value, which--in the case of ReadFile under Windows 95/98--is the
only valid value, according to my copy of the MSDN Library.
Problem is, I can't find a way to emulate this in VB.
I've tried the most obvious solution (Null)...of course that wouldn't work. I
tried passing 0 and 0&...I got "ByVal argument type mismatch". I tried the VB
constants...no luck there. I tried messing around with the undocumented xxxPtr
functions...and I think I crashed my computer somehow with that.
Anybody know how to accomplish tis?
And for that matter, can anybody help me use ReadFile in VB? =)
--David