Passing a NULL value to API parameters that take UDTs 
Author Message
 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



Tue, 21 Aug 2001 03:00:00 GMT  
 Passing a NULL value to API parameters that take UDTs
Change As OVERLAPPED to As Any. Alternatively, you can
declare the function twice, with different parameter lists and
different aliases.

Quote:

>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?
<snip>
>--David



Tue, 21 Aug 2001 03:00:00 GMT  
 Passing a NULL value to API parameters that take UDTs

<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.

Hi David,

When C passes a null pointer, VB needs to pass a 0& ByVal.
Change the  declaration  to pass the  last parameter ByVal
as Long and pass a 0&.

HTH

--
Paul Marshall



Tue, 21 Aug 2001 03:00:00 GMT  
 Passing a NULL value to API parameters that take UDTs
You can also pass vbNullString for Null... either ByVal vbNullString as
string, or ByVal 0& as long....

Michael


Quote:

> <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.

> Hi David,

> When C passes a null pointer, VB needs to pass a 0& ByVal.
> Change the  declaration  to pass the  last parameter ByVal
> as Long and pass a 0&.

> HTH

> --
> Paul Marshall




Tue, 21 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to pass single, multiple or null parameter value(s) to multiple queries

2. Passing NULL value to report parameter

3. Passing NULL parameter to API function

4. How can I pass NULL value to WinAPI which is expecting a NULL pointer

5. CAN ADODB.PARAMETER VALUE BE NULL?

6. Parameter Query/Null Value help

7. Passing null parameters

8. Passing Null parameters to SQL Server

9. Null values in Parameter queries (or Wildcards)???

10. Null values in Parameter queries (or Wildcards)???

11. How to pass NULL for interface pointer parameter?

12. Passing Null Parameters (sorry, lengthy)

 

 
Powered by phpBB® Forum Software