Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How Can I Use Dll In Perl


  • Please log in to reply
3 replies to this topic

#1 lshjhonker

lshjhonker

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Location:China
  • Local time:07:29 PM

Posted 25 June 2008 - 04:13 AM

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 B)',
);
$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 B)',
);
$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
http://0xx.org.cn http://www.91one.net 洞庭波兮木叶下

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:29 AM

Posted 25 June 2008 - 10:05 AM

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.

#3 lshjhonker

lshjhonker
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Location:China
  • Local time:07:29 PM

Posted 26 June 2008 - 02:02 AM

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 .
http://0xx.org.cn http://www.91one.net 洞庭波兮木叶下

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:29 AM

Posted 26 June 2008 - 06:32 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users