Click here to get back home

Calling External DLL functions in Perl using Inline

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Calling External DLL functions in Perl using Inline Sankaran 07-11-2005
Posted by Sankaran on July 11, 2005, 6:47 am
Please log in for more thread options


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;
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1>Perl Hello.Pl

Microsoft (R) Program Maintenance Utility Version 6.00.9782.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

mkdir blib
mkdir blib\lib
mkdir blib\arch
mkdir blib\arch\auto
mkdir blib\arch\auto\Hello_Pl_74c2
mkdir blib\lib\auto
mkdir blib\lib\auto\Hello_Pl_74c2
D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
D:\Perl\lib\ExtUtils/xs
ubpp -typemap D:\Perl\lib\ExtUtils\typemap Hello_Pl_74c2.xs >
Hello_Pl_74c2.xsc
&& D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
-MExtUtils::Command -e mv H
ello_Pl_74c2.xsc Hello_Pl_74c2.c
cl -c
-IE:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1 -O1 -M
D -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT
-DPERL_IMPLICIT_CONT
EXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX -O1 -MD -DNDEBUG
-DVERSION=\"
0.00\" -DXS_VERSION=\"0.00\" -ID:\Perl\lib\CORE Hello_Pl_74c2.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Hello_Pl_74c2.c
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2054: expected '(' to follow 'class'
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2085: 'CInlinetestLib' : not in formal parameter list
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2143: syntax error : missing ';' before '{'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.

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\Hello_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



Posted by Sisyphus on July 12, 2005, 5:18 am
Please log in for more thread options



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




Posted by Sankaran on July 11, 2005, 11:37 pm
Please log in for more thread options


Hello

I am getting the following out put
______________________________________
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1>perl Hello.Pl
Starting Build Prepocess Stage
Finished Build Prepocess Stage

Starting Build Parse Stage
Finished Build Parse Stage

Starting Build Glue 1 Stage
Finished Build Glue 1 Stage

Starting Build Glue 2 Stage
Finished Build Glue 2 Stage

Starting Build Glue 3 Stage
Finished Build Glue 3 Stage

Starting Build Compile Stage
Starting "perl Makefile.PL" Stage
Note (probably harmless): No library found for '-lInlinetestLib'
Writing Makefile for Hello_Pl_5dd0
Finished "perl Makefile.PL" Stage

Starting "make" Stage

Microsoft (R) Program Maintenance Utility Version 6.00.9782.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
D:\Perl\lib\ExtUtils/xs
ubpp -typemap D:\Perl\lib\ExtUtils\typemap Hello_Pl_5dd0.xs >
Hello_Pl_5dd0.xsc
&& D:\Perl\bin\Perl.exe -ID:\Perl\lib -ID:\Perl\lib
-MExtUtils::Command -e mv H
ello_Pl_5dd0.xsc Hello_Pl_5dd0.c
cl -c
-IE:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1 -I\E:\
Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1 -O1 -MD -DNDEBUG
-DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT
_SYS -DPERL_MSVCRT_READFIX -O1 -MD -DNDEBUG -DVERSION=\"0.00\"
-DXS_VERSIO
N=\"0.00\" -ID:\Perl\lib\CORE Hello_Pl_5dd0.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Hello_Pl_5dd0.c
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2054: expected '(' to follow 'class'
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2085: 'CInlinetestLib' : not in formal parameter list
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15)
:
error C2143: syntax error : missing ';' before '{'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.

A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
nmake

The build directory was:
E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1\_Inline\build\Hello_Pl
_5dd0

To debug the problem, cd to the build directory, and inspect the output
files.

at Hello.Pl line 8
BEGIN failed--compilation aborted at Hello.Pl line 17.
________________________________________________________
for the below modified program...
use warnings;

use Inline C => Config =>
LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1
-lInlinetestLib',
INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1',
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__
________________________________________________________
I have modified your program.
Any clue?

Regards,
Sankaran



Posted by Sisyphus on July 13, 2005, 1:26 pm
Please log in for more thread options




> Starting Build Compile Stage
> Starting "perl Makefile.PL" Stage
> Note (probably harmless): No library found for '-lInlinetestLib'

Nope - it's not harmless. InlinetestLib.lib needs to be found. Where is it ?
(I think it might have been created when you built the dll ... but I'm not
sure about that.)
If you don't have it, can you tell me how the dll was built - ie which
command(s) did you run.

[snip]

> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
> 80x86
> Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
>
> Hello_Pl_5dd0.c
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
)
> :
> error C2054: expected '(' to follow 'class'
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
)
> :
> error C2085: 'CInlinetestLib' : not in formal parameter list
>
E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
)
> :
> error C2143: syntax error : missing ';' before '{'
> NMAKE : fatal error U1077: 'cl' : return code '0x2'
> Stop.

The compiler doesn't like the way InlineTestLib.h is written. Did you get
the same problems when you built the dll ?

> ________________________________________________________
> for the below modified program...
> use warnings;
>
> use Inline C => Config =>
> LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1
> -lInlinetestLib',

The location is incorrectly specified. Perhaps that's why the file can't be
found. Should be:
LIBS => '-LE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1

> INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1',

Change to:
INC => '-IE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1',

> 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




Posted by ben.sommer on July 21, 2005, 12:38 pm
Please log in for more thread options


Sisyphus wrote:
>
> > Starting Build Compile Stage
> > Starting "perl Makefile.PL" Stage
> > Note (probably harmless): No library found for '-lInlinetestLib'
>
> Nope - it's not harmless. InlinetestLib.lib needs to be found. Where is it ?
> (I think it might have been created when you built the dll ... but I'm not
> sure about that.)
> If you don't have it, can you tell me how the dll was built - ie which
> command(s) did you run.
>
> [snip]
>
> > Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
> > 80x86
> > Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
> >
> > Hello_Pl_5dd0.c
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
> )
> > :
> > error C2054: expected '(' to follow 'class'
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
> )
> > :
> > error C2085: 'CInlinetestLib' : not in formal parameter list
> >
> E:/Sankaran/Work/TP-TAImpacts-LM051049/PerlInline/MyTest1\InlinetestLib.h(15
> )
> > :
> > error C2143: syntax error : missing ';' before '{'
> > NMAKE : fatal error U1077: 'cl' : return code '0x2'
> > Stop.
>
> The compiler doesn't like the way InlineTestLib.h is written. Did you get
> the same problems when you built the dll ?
>
> > ________________________________________________________
> > for the below modified program...
> > use warnings;
> >
> > use Inline C => Config =>
> > LIBS => '-L\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1
> > -lInlinetestLib',
>
> The location is incorrectly specified. Perhaps that's why the file can't be
> found. Should be:
> LIBS => '-LE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1
>
> > INC => '-I\E:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1',
>
> Change to:
> INC => '-IE:\Sankaran\Work\TP-TAImpacts-LM051049\PerlInline\MyTest1',
>
> > 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


Hi All.

I'm just wondering how this problem resolved for you, Sankaran. I have
the (almost) exact same problem, though my environment is cygwin+gcc.
The user32.dll example from the Inline docs works flawlessly for me as
well. Also, for my application, any conceivable permutation of the INC
or LIBS directives (and windows/cygwin LIB/INC/PATH environment
variables) always results in this:

Note (probably harmless): No library found for '-lMyLib'

Pretty frustrating!


Thanks for reading,
--
Ben Sommer
Senior Technology Officer
Eastern Nazarene College
23 East Elm Ave
Quincy, MA 02170



Similar ThreadsPosted
Calling external dll from inline perl using gcc on XP May 19, 2006, 2:48 am
Getting Path of an external DLL in Perl: Inline C. October 2, 2005, 8:41 pm
Calling C++ / MFC / SDKs usinf Inline July 16, 2005, 12:36 am
How can I call MFC functions from Perl July 19, 2005, 9:46 pm
Using external REXX function libraries with PERL October 1, 2007, 2:40 pm
Module for Orchestrating Perl Functions? May 9, 2008, 9:30 pm
Perl interface to direct port I/O functions (inb(), outb() and friends) February 19, 2005, 9:00 pm
PLJava - Perl embeded into Java (calling Perl from Java) - 1sr release - call for tests and review, please. July 13, 2004, 4:06 am
Error calling Win32::Printer from a perl script hosted in IIS on Win2k3 June 3, 2008, 8:53 am
Error calling Win32::Printer from a perl script hosted in IIS on Win2k3 June 3, 2008, 8:57 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap