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();
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;
2) API Syntax: long GetVersion(char *pstrBuf, long lBuf);
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;
3) API Syntax: long OpenConnection(char *strDataSource, char *strUser, char *strPwd);
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.