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

This reminds me of similar struggles that I had about a year ago. I posted a question about my situation (How to use Win32::API to access variable in DLL file?) and got very useful help from BrowserUk about how accomplish what I wanted using just the Win32 module. You might want to check it out to see if the information there might help you get started.

Of course, that was dealing with variables. For functions, you would use Win32::API. The combination of the post linked above and some sample code below might help get you going in the right direction.

use strict; use Win32::API; # Load the DLL my $dll = Win32::LoadLibrary('CrappyLibrary.dll') || die $^E; # Import the function my $func = new Win32::API('CrappyLibrary.dll','RegisterClient2','PP',' +I'); if (not defined $func) {die "Unable to import 'RegisterClient2' functi +on.\n";} my $client_id = 1; my $ip_addr = "192.168.1.1"; # Call the function my $value = $func->Call($client_id,$ip_addr); # unload DLL Win32::FreeLibrary($dll);

Hope this helps!

  • Comment on Re: Calling a function form an external DLL with Inline::C on windows
  • Download Code

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 09:20 UTC
    If I try it with this syntax ('PP', 'I'), the perl interpreter crashes (I get that lovely "The program Perl Command Line Interpreter encountered an error and needs to close" dialog box.)