in reply to Passing/Returning HANDLE's with Win32::API

I believe your declaration for WNetEnumResource is wrong: The MSDN declares it as

DWORD WNetEnumResource( HANDLE hEnum, LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize );

which I interpret as LPPP and not as PPPP. Try it with the following code:

my $WNetEnumResource= new Win32::API ("mpr", "WNetEnumResource", "VPPP +", "I") or die; my $count= pack ("V", -1); my $bufsize= 5000; $buffer= 'x' x (1+$bufsize); for (;;) { $bufsize= pack ("V", 5000); $result= $WNetEnumResource->Call ($handle, $count, $buffer, $bufsiz +e); print "result for WNetEnumResource is $result\n"; last if $result != 0; print "count=$count, bufsize=$bufsize\n"; print $buffer; # just to see if it's not all x's. }

Updated: The prototype should have been LPPP, and not VPPP

Replies are listed 'Best First'.
Re^2: Passing/Returning HANDLE's with Win32::API
by John M. Dlugosz (Monsignor) on Feb 07, 2005 at 23:31 UTC
    Then it tells me that the argument is not numeric. The HANDLE received out of the first function is a 4-byte opaque cookie.

      Treat this opaque cookie as a number, that is, unpack it, and then pass it in again:

      $handle = unpack "V", $handle; ....
        I see.

        What Win32::API needs is a way to specify a pointer to a DWORD "number", rather than using P which doesn't treat the value the same way as N and I.