Re: Calling External DLL functions in Perl using Inline
- From: "Sisyphus" <sisyphus1@xxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Jul 2005 05:18:05 +1000
"Sankaran" <psankarv@xxxxxxxxx> wrote in message
news:1121089632.521430.234120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello
I am trying to call a DLL function from Perl using Inline as follows
use Inline C => DATA =>
LIBS => '-lInlinetestLib';
greet();
__END__
__C__
#include "InlinetestLib.h"
void greet(){
int nId = fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");}
Where:
InlinetestLib is a test dll with 1 exported function fnInlinetestLib()
I am getting the following error while I am trying to run this;
[snip]
A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
nmake > out.make 2>&1
The build directory was:
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1\_Inline\build\Hell
o_Pl
_74c2
To debug the problem, cd to the build directory, and inspect the output
files.
at Hello.Pl line 0
INIT failed--call queue aborted.
But when I am trying a sample which I got from net, it is running fine.
The example which I tried is
use Inline C => DATA =>
LIBS => '-luser32',
PREFIX => 'my_';
MessageBoxA('Inline Message Box', 'Just Another Perl Hacker');
__END__
__C__
#include <windows.h>
int my_MessageBoxA(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);
}
This is displaying a MessageBox as the output.
My doubts are;
· Where should be the .h file contains the exported interface?
· Path of LIB file and DLL?
· Is it necessary to provide my DLL / LIB path in the environment
PATH variable? (I have already added the DLL / LIB / .H file path in
the PATH variable)
Kindly provide the guidelines incase if any, so that it will help me.
Regards,
Sankaran
----------------------------------------------------------------------------
-----
You can specify the location of LIBS (InlinetestLib.lib) and INC
(InlinetestLib.h) as below.
Note that you need to link to the import lib 'InlinetestLib.lib' (just as
you linked to user32.lib in the above example) because MSVC++ is incapable
of linking directly to the dll. If you don't have an import lib, then you'll
need to make one.
You don't need to provide the path to user32.lib because that gets found
automatically - and you also don't need to tell the compiler where windows.h
is, because that too gets found ok. But you will need to tell the compiler
where InlinetestLib.lib is located (hence the
-L/path/to/your_import_lib below), and you'll need to tell the compiler
where InlinetestLib.h is located (hence the
-I/path/to/your_include_file below).
You can use the layout you used above for your Inline script if you like.
I've provided a slightly different layout below, because that's the layout
I'm more familiar with. (I've also specified BUILD_NOISY so that you see
what's happening as the script compiles the first time you run it.)
use warnings;
use Inline C => Config =>
LIBS => '-L/path/to/your_import_lib -lInlinetestLib',
INC => '-I/path/to/your_include_file',
BUILD_NOISY => 1;
use Inline C => <<'EOC';
#include "InlinetestLib.h"
void greet(){
int nId = fnInlinetestLib();
printf ("%d", nId);
printf("Hello, world from Perl Inline, By Sankaran\n");
}
EOC
greet();
__END__
Cheers,
Rob
.
- Follow-Ups:
- Re: Calling External DLL functions in Perl using Inline
- From: Sankaran
- Re: Calling External DLL functions in Perl using Inline
- References:
- Calling External DLL functions in Perl using Inline
- From: Sankaran
- Calling External DLL functions in Perl using Inline
- Prev by Date: LWP problems
- Next by Date: Re: Reusing SQL data-related logic, replacing weird modules and improving Class::DBI
- Previous by thread: Calling External DLL functions in Perl using Inline
- Next by thread: Re: Calling External DLL functions in Perl using Inline
- Index(es):
Relevant Pages
|
|