in reply to Calling a function form an external DLL with Inline::C on windows

If int* doesn't work, I would use the following. It's basically the same as what you ended up doing using Inline::C, but in Pure Perl.

use Win32::API qw( ); my $register_client2 = Win32::API->new( $S{DLL_path}, 'RegisterClient2', 'PP', 'I', ); sub register_client2 { my $ip = $_[1]; my $id = pack('l', 0); # Allocate space my $rv = $register_client2->Call($id, $ip); $_[0] = unpack('l', $id); return $rv; } register_client2(my $id, $ip) or die;

If the return value is just a boolean, you could do something more perlish.

sub register_client2 { my ($ip) = @_; my $id = pack('l', 0); # Allocate space $register_client2->Call($id, $ip) or return (); return unpack('l', $id); } my ($id) = register_client2($ip) or die;

Note: psz would indicate char** rather than char*. That's confusing.

Replies are listed 'Best First'.
Re^2: Calling a function form an external DLL with Inline::C on windows
by Anonymous Monk on Aug 06, 2010 at 15:05 UTC
    It turns out that my entire trip to Inline-land was useless1, because Win32::SerialPort doesn't work for some reason if I use it.

    However, I tried Win32::API again as a last resort, and it turned out that it works (and it doesn't crash) if and only if I import the functions like this:

    my $RegisterClient2 = Win32::API->new($DLL, 'RegisterClient2', 'PP', ' +I', '_cdecl');

    So my DLL was compiled with the _cdecl convention, and that's why it failed earlier.

    1) not entirely useless, because I used to think that I can't use Inline on Windows at all. Now that I saw that it works, I have plans to rewrite some of the speed-critical parts of my earlier applications.

    2) I agree that the DLL writer's version of Hungarian notation is confusing, but I can't do anything about it. I decided to go with it to stay in sync with the docs.