Dear Friends, I am writing to call the APIs (functions) in the C DLL using perl CPAN Module Win32::API. The code works fine in the case where API expects input variable as Long. When the API expects the input as char *, i am not getting expected results. In the below, API, (1) and (2) are working fine. But API (3) has input parametes as char *. The result is signed long. In the working case, the result should return value greater than zero. but i am getting result as zero. Could you please advice me, how to pass the value as char * (C datatype) to the API as expected by API. Thanks in advance. Regards, Rags
DLL : mydll.dll
1) API Syntax: long CurrentDate();2) API Syntax: long GetVersion(char *pstrBuf, long lBuf);use Win32::API; my $dec = Win32::API->new('mydll.dll', 'CurrentDate', '', 'L') or die +$^E; my $rv_bstr = $dec->Call(); ($sec,$min,$hour,$day,$month,$year) = localtime($rv_bstr); # correct the date and month for humans $year = 1900 + $year; $month++; printf "%02d/%02d/%02d %02d:%02d:%02d\n", $year, $month,$day, $hour, $ +min, $sec;
3) API Syntax: long OpenConnection(char *strDataSource, char *strUser, char *strPwd);use Win32::API; my $dec = Win32::API->new('mydll.dll', 'GetVersion', 'PN', 'L') or die + $^E; my $lpBuffer = " " x 64; $return = $dec->Call($lpBuffer, 64); print $lpBuffer;
use Win32::API; my $dec = Win32::API->new('mydll.dll', 'OpenConnection', 'PPP', 'L') o +r die $^E; $strDatabase = "test"; $strLoginUser = "test"; $strLoginPwd = "test"; # converting to C String $db = pack('a*x', $strDatabase); $user = pack('a*x', $strLoginUser); $pwd = pack('a*x', $strLoginPwd); $return = $dec->Call($db, $user, $pwd); print $return;
In reply to Call C DLL Functions in Perl by sraghu_rs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |