anupama has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to call C++ Dll from perl using WIN32API
my Test.cpp file
extern "C" __declspec(dllexport);
int __stdcall test(int x)
{
x *= 2;
return x;
}
Test.h file
extern "C" __declspec(dllexport) int test(int);
#NOTE:Iam compling the above cpp file using Visual Studio 2005
perl file Test.pl
use strict;
use warnings;
use Win32::API;
use Win32::API::Callback;
use Win32::API::Test;
my $fun = Win32::API->new('Test.dll', 'int test(int a)') or die $^E;
my $Result = $fun->call(12);
print "$Result\n";
while executing the above perl script error msg pops up
The specified procedure could not be found at Test.pl line 17.
Please let me know where i m going wrong(Script as well cpp file).
Is there anything that i've missed during complation of cpp files?
  • Comment on need help while calling C++ Dll from Perl using Win32Api

Replies are listed 'Best First'.
Re: need help while calling C++ Dll from Perl using Win32Api
by Anonymous Monk on Mar 03, 2009 at 08:53 UTC
Re: need help while calling C++ Dll from Perl using Win32Api
by Anonymous Monk on Mar 03, 2009 at 09:42 UTC
      Hi, Iam using Active perl Windows to execute the perl script.
      Here i download the Win32::API from CPAN directly.
      Downloaded strawberry-perl-5.8.8-alpha-1.exe and installed in my PC.
      strawberry-perl-5.8.8-alpha-1.exe perl got installed in c:\Strawberry-perl.
      When i copied the required files to C:\strawberry-perl\perl\bin.
      when i executed my Test.pl script from cmd line error pops up saying :
      C:\strawberry-perl\perl\bin>perl Test.pl
      Can't locate loadable object for module Win32::API in @INC (@INC contains: C:/strawberry-perl/perl/lib C:/strawberry-perl/perl/site/lib .) at Test.pl line 6
      Compilation failed in require at Test.pl line 6.
      BEGIN failed--compilation aborted at Test.pl line 6.
      The above intreputs that Win32::API module is not downloaded
      Should i download Win32::API from CPAN or is it Downloaded during installation of strawberry-perl
        When i copied the required files to C:\strawberry-perl\perl\bin.
        What files? All you should need is
        C:\>cpanp i Win32::API
        to install Win32::API
      Hi,
      As you suggested installed Strawberry perl and ran the perl script it worked
      . Thanks a lot
      Thanks, Anupama N
Re: need help while calling C++ Dll from Perl using Win32Api
by Anonymous Monk on Mar 03, 2009 at 09:19 UTC
    Case matters, its ->Call not ->call.