开发者

accessing dll from perl

I am trying to access some win32 api function by using Win32::API module below is my code开发者_开发百科 :

The code is run but the result is 0 (no success ). could someone advice if there are a problem with the below code or if there a problem of transferring the values from perl side to c side.

my $site = 'http://www.test_site.cn/\0';
my $key =0; #NULL
my $value ='data=testdata; expires = Thu, 15-Nov-2010 15:08:00 GMT\0';

my $InternetSetCookie = Win32::API->new('Wininet.dll', 'BOOL InternetSetCookie(
  LPCTSTR lpszUrl,
  LPCTSTR lpszCookieName,
  LPCTSTR lpszCookieData)'
);

my $res = $InternetSetCookie->Call($site,$key,$value);

if ($res) {
  print 'success';
}


The problem may be that you have an underscore in the hostname, which I believe is not valid. I tried the code exactly as you posted and got an error The parameter is incorrect.. If I removed the underscore (e.g., testsite), then the API returned true.

You might add the following to print the error message for failures; it will give a bit more information on the reason for the failure.

print Win32::FormatMessage( Win32::GetLastError() );


Two things jump out at me:

One, you use single-quoted string with the character sequence \0 in them, which is probably not what you want. Use double-quoted strings to interpolate that sequence to the NUL character, or append it separately:

my $site = "http://www.test_site.cn/\0";
my $value ='data=testdata; expires = Thu, 15-Nov-2010 15:08:00 GMT' . chr(0);

Second, you set $key to 0 but your comment indicates that you think it is setting it to NULL. Perl is very promiscuous flexible about treating numbers as strings and vice versa, so as a result you are probably passing the string value "0" to the DLL function (and possibly without a NUL character at the end of the string). You might try one of

my $key = '';
my $key = "\0";

Also, check $! and $^E for other error messages set by Perl and Windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜