There occurs a problem when I tried to use dll in perl.
I create a dll just like this: (Borland C++ Builder)
#include <windows.h>
#pragma argsused
extern "C" __declspec(dllexport) int fac(int n);
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
int fac(int n)
{
if(n==0)
return 1;
else
return(n*fac(n-1));
}
It can be used well in another project. (Borland C++ Builder)
On CPAN,it performs three methods which tells us how to use dll in perl with the module Win32-API:
use Win32::API;
$function = Win32::API->new(
'mydll, 'int sum_integers(int a, int
);
$return = $function->Call(3, 2);
#### Method 2: with parameter list
use Win32::API;
$function = Win32::API->new(
'mydll', 'sum_integers', 'II', 'I',
);
$return = $function->Call(3, 2);
#### Method 3: with Import
use Win32::API;
Win32::API->Import(
'mydll', 'int sum_integers(int a, int
);
$return = sum_integers(3, 2);
Just like that,I create a perl script.In the script I want to use the function :
int fac ( int n )
The script like this:
#!usr/bin/perl -w
use Win32::API;
$a=int 5;
Win32::API->Import('fac.dll','int fac(int n)');
$result=fac($a);
print $result;
When Running ,It says Undefined subroutine &main::fac called.
Maybe the dll which I created is not standard dll.
Well,can anyone tells me the method of create standard dll.or if the dll I created is OK ,can anyone tells me how to use dll in Perl.
Thank You All !
lshjhonker