Help - Search - Members - Calendar
Full Version: How Can I Use Dll In Perl
BleepingComputer.com > Software > Programming
   
lshjhonker
Hello , Everyone!

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 cool.gif',
);
$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 cool.gif',
);
$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
groovicus
For starters, what do you think you are doing here?
$a=int 5;

Are you trying to assign an integer to $a? I have never seen syntax like that. Perl is not a strongly typed language, so all you would need to do (assuming that all you are doing is trying to assign 5 to $a) is to do $a=5. Perl is smart enough to look at the value there and know it is an int.

I'll be the first to admit to not being an expert in Perl; far from it, so maybe you are doing something that I have never seen before. I just want to clear that up first.

lshjhonker
Well,at first I tried
...
$result=fac(5);
...

and

...
$a=5;
$result=fac($a);
...


The result is the same.At last,I tried
...
$a=int 5;
...


I haved tried the DLLs supply by MicroSoft,It just works well.
Maybe the problem is just How I can create a standard dll by BCB.

Thank You , groovicus .
groovicus
The problem is that you are passing your dll a string, not an int. Since the script is looking for a function that takes a string, which it can't find, it is saying that the function does not exist.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.