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

Then it tells me that the argument is not numeric. The HANDLE received out of the first function is a 4-byte opaque cookie.
  • Comment on Re^2: Passing/Returning HANDLE's with Win32::API

Replies are listed 'Best First'.
Re^3: Passing/Returning HANDLE's with Win32::API
by Corion (Patriarch) on Feb 07, 2005 at 23:33 UTC

    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.

        Win32::API treats the "P" prototype as "any" pointer - it is opaque to Win32::API and you need to post-process the value with pack>/tt> and unpack. This is not as nice as it could be, but as you are interfacing with C-level subroutines anyway, some knowledge about the stuff is needed anyway. You might have success by using the C-prototype version of Win32::API, that tries to interpret the C-prototypes of functions, but then you would need to find a way to tell Win32::API what a hFOO is without Win32::API having access to the relevant include and header files. See Convert::Binary::C for a module that does this task, and also for how ugly that way is, as Convert::Binary::C needs to implement its own C preprocessor for tracing the include statements of header files.