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

Hi all,
Using the Win32::API lib, I want to import the following C function:
USHORT RscIoCheck (ULONG ulConnectionHandle ,ULONG ulSessionHandle ,SHORT *pnIoHandle ,VOID *pvReplyBuffer ,USHORT *puReplySize );
which is found in the "Rscw32.dll". To import it, I have the following script:
use Win32::API 0.40; my $sFuncRscIoCheck = new Win32::API('Rscw32', 'RSCCHK', 'IIPPP', 'I') +;
When I use it, I call the function as follow:
my $sReturn; my $sIoHandle = RSC_IO_NOWAITED; my $sCheckAll = RSC_IO_CHECK_ALL; $sReturn = $sFuncRscIoCheck->Call($sConnectionHandle, $sSessionHandle, $sCheckAll, $sReplyBuffer, $sReplySize);
I'm expecting a return value of '17' but when I print the "$sReturn", I got '33685510'.

If I do the following:
my $sReturn = pack('S', 0); $sReturn = $sFuncRscIoCheck->Call($sConnectionHandle, $sSessionHandle, $sCheckAll,<br> $sReplyBuffer, $sReplySize); $sReturn = unpack('S', $sReturn);
print "My Return is : $sReturn\n";

the "$sReturn" value is set to '13107' and this value can (and probably will) change if I reboot the PC.
Is it possible to handle the USHORT correctly with the Win32::API lib?
Any idea?
Thanks,
ptk

Note: Even if the return value is incorrect, the function seems to work!

Edit by BazB: add code tags.

Replies are listed 'Best First'.
Re: Win32::API to import function
by esskar (Deacon) on Feb 28, 2005 at 20:38 UTC
    have you tried
    my $sFuncRscIoCheck = new Win32::API('Rscw32', 'USHORT RscIoCheck(ULON +G ulConnectionHandle,ULONG ulSessionHandle,SHORT *pnIoHandle,VOID *pv +ReplyBuffer,USHORT *puReplySize)');
    ?
      If I use the following line to import the function:

      Win32::API->Import('Rscw32', 'USHORT RSCCHK(ULONG ulConnectionHandle,ULONG ulSessionHandle,SHORT *pnIoHandle,VOID *pvReplyBuffer,USHORT *puReplySize)');

      I have a crash at this line (i.e. as soon as I use it):

      $sReturn = RSCCHK($sConnectionHandle,
      $sSessionHandle,
      $sCheckAll,
      $sReplyBuffer,
      $sReplySize);

      Note: To import the "RscIoCheck" function, I need to use his API function name "RSCCHK".
        I have try the "Import" and the following:

        my $sFuncRscIoCheck = new Win32::API('Rscw32', 'USHORT RSCCHK(ULONG ul +ConnectionHandle,ULONG ulSessionHandle,SHORT *pnIoHandle,VOID *pvRepl +yBuffer,USHORT *puReplySize)'); $sReturn = $sFuncRscIoCheck->Call($sConnectionHandle, $sSessionHandle, $sCheckAll, $sReplyBuffer, $sReplySize);

        They crash the perl interpreter with the Win error message: "Perl Command Line Interpreter has encountered a problem and needs to close. We are sorry for the inconvenience.".

        Any other idea?