in reply to need help while calling C++ Dll from Perl using Win32Api

If you have strawberryperl, this works
C:\perlmonks747643>ls -lh total 12K -rw-rw-rw- 1 666 0 126 2009-03-03 01:31 myTest.cpp -rw-rw-rw- 1 666 0 49 2009-03-03 01:30 myTest.h -rw-rw-rw- 1 666 0 248 2009-03-03 01:35 myTest.pl C:\perlmonks747643>cat myTest.h extern "C" __declspec(dllexport) int test(int); C:\perlmonks747643>cat myTest.cpp #include "myTest.h" extern "C" __declspec(dllexport) int __stdcall test(int x) { x *= 2; return x; } C:\perlmonks747643>cat myTest.pl #!/usr/bin/perl -- use strict; use warnings; use Win32::API; use Win32::API::Callback; use Win32::API::Test; my $fun = Win32::API->new('myTest.dll', 'int test(int a)') or die $^E; my $Result = $fun->Call(12); print "12 * 2 = $Result\n"; C:\perlmonks747643>gcc -shared -o myTest.dll myTest.cpp -Wl,--add-stdc +all-alias C:\perlmonks747643>ls -lh total 28K -rw-rw-rw- 1 666 0 126 2009-03-03 01:31 myTest.cpp -rw-rw-rw- 1 666 0 13K 2009-03-03 01:36 myTest.dll -rw-rw-rw- 1 666 0 49 2009-03-03 01:30 myTest.h -rw-rw-rw- 1 666 0 248 2009-03-03 01:35 myTest.pl C:\perlmonks747643>perl myTest.pl 12 * 2 = 24 C:\perlmonks747643>pexports -v myTest.dll ; .text: RVA: 00001000, File offset: 00000400 ; .data: RVA: 00002000, File offset: 00000c00 ; .rdata: RVA: 00003000, File offset: 00000e00 ; .bss: RVA: 00004000, File offset: 00000000 ; .edata: RVA: 00005000, File offset: 00001000 ; Reading exports from section: .edata ; Export table: myTest.dll ; Ordinal base: 1 ; Ordinal table RVA: 00005038 ; Name table RVA: 00005030 ; Export address table RVA: 00005028 LIBRARY myTest.dll EXPORTS test ; .text ; RVA 00001180 test@4 ; .text ; RVA 00001180 ; .idata: RVA: 00006000, File offset: 00001200 ; .reloc: RVA: 00007000, File offset: 00001400 C:\perlmonks747643>

Replies are listed 'Best First'.
Re^2: need help while calling C++ Dll from Perl using Win32Api
by Anonymous Monk on Mar 03, 2009 at 11:22 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
Re^2: need help while calling C++ Dll from Perl using Win32Api
by anupama (Novice) on Mar 05, 2009 at 05:41 UTC
    Hi,
    As you suggested installed Strawberry perl and ran the perl script it worked
    . Thanks a lot
    Thanks, Anupama N