cbrauner has asked for the wisdom of the Perl Monks concerning the following question:

how i handle a pointer to dword in win32::api ? eg. my dll contains a simple function void CheckLen(DWORD *len); how i should define/initialise this function with win32::api for using in perl (as pointer ?, memory must be allocated?) ?

Replies are listed 'Best First'.
Re: Win32::API and pointer of dword
by ikegami (Patriarch) on Aug 18, 2009 at 13:59 UTC

    I think the following would do:

    my $CheckLen = Win32::API->new('...', 'CheckLen', 'P', 'V') or die ...; sub CheckLen { $len = pack('L', $_[0]); $CheckLen->Call($len); $_[0] = unpack('L', $len); }

    Of course, you could also try the prototype method of loading your function.

      yea i tried this wiwth pack/unpack the only issue i have is with initialisation of len=0 : in my c function i have a check: if len==0 return ERROR, but this doesnt get called ..? thx

      GrandFather restored original content

      yea i tried this with pack/unpack the only issue i have is with initialisation of len=0 : in my c function i have a check: if len==0 return ERROR, but this doesnt get called ..? thx

      GrandFather restored original content

        len is will never be NULL pointer. It'll never be zero. If you want the ability to pass NULL, we'll have to do more work. Which of the following is true?

        • Did you mean to allow NULL to be passed?
        • Did you forget to dereference len?
        • Was choosing to pass a pointer a mistake?

        And then there's return ERROR; in a function of return type void...

        Show your code, not a description