Re: Calling External DLL functions in Perl using Inline




<ben.sommer@xxxxxxx> wrote

> Taking that DLL example from the Inline::C cookbook...
>
> http://search.cpan.org/~ingy/Inline-0.44/C/C-Cookbook.pod#Win32
>
> use Inline C => DATA =>
> LIBS => '-luser32';
>
> $text = "@ARGV" || 'Inline.pm works with MSWin32. Scary...';
>
> WinBox('Inline Text Box', $text);
>
> __END__
> __C__
>
> #include <windows.h>
>
> int WinBox(char* Caption, char* Text) {
> return MessageBoxA(0, Text, Caption, 0);
> }
>
>
> That config directive "LIBS => '-luser32'" looks pretty key right? It
> says 'go call "user32.dll", right? Wrong. It does nothing. Remove it
> and the code compiles and runs the same.

No - I think that LIBS directive is saying "link to libuser32.a" - which you
should find in Cygwin's gcc/lib folder.
I think that script builds ok when you remove the LIBS directive because
libuser32.a is linked to automatically. That automatic linking is built in
by the ExtUtils modules. To verify, insert the following at the top of the
script:

use Inline C => Config =>
BUILD_NOISY => 1;

Then make some change to the C code in that script (to force it to rebuild -
add or delete some white space is sufficient).

Then re-run the script. Somewhere in the output you should see 'libuser32.a'
mentioned (along with a heap of other libs).

> Its the windows.h include file
> that makes this example - and probably all Win32 dlls - work under
> cygwin, thanks to all the hand-rolled header files in
> /usr/include/w32api.

You'll possibly find you don't even have to specifically include windows.h
either. Your Inline::C code will automatically include 'perl.h' and that
might lead to the inclusion of 'windows.h'. On my perls that's the way it
is, anyway. 'perl.h' includes 'win32.h' which includes 'windows.h'. It might
be different under Cygwin.

> I'd love to hear from people using Inline::C under
> cygwin with gcc and a _custom_ DLL file.
> How do you manage to link it.

To link directly to a dll (which is possible with gcc, but not with
Microsoft compilers) you specify the 'MYEXTLIB' config directive - eg:

MYEXTLIB => "/full_path/to_dll/MyDLL.dll",

> How do are you able to include your own header files?

You just list them as you would in normal C code. You can use the 'INC'
config directive to specify the directory that they are in (if they're not
already in some standard location):

INC => "-I/full_path/to_folder/that_contains/my_includes",

> Please prove me
> wrong! I'd even listen to people having success with ActiveState perl
> and Visual Studio (ugh).

I use gcc (MinGW) most of the time - but that's using 'gcc' in a native
Win32 environment - not in a Cygwin environment. I also use MSVC++ 7.0
(.NET) which is a very good compiler - though, for me, a little cumbersome
to use. I prefer to use MinGW as I find I'm a lot more comfortable with it.
I would never use Cygwin - for various reasons (most of which don't apply to
everybody .... or do I mean "anybody" ? :-).

>Off to post to the cygwin list...
>

For Inline::C questions, the best forum is the Inline mailing list. (See
http://lists.perl.org/index.cgi :-)

Cheers,
Rob


.



Relevant Pages

  • Re: Calling External DLL functions in Perl using Inline
    ... >> and the code compiles and runs the same. ... > I think that script builds ok when you remove the LIBS directive because ... > be different under Cygwin. ... >> How do are you able to include your own header files? ...
    (comp.lang.perl.modules)
  • Re: "Attempt to execute non-executable address" on Server 2008 when ??Terminal Services installe
    ... Is the function being called in a DLL or in the EXE? ... BaseAddress: 0040d000 ... So *something* has actually changed the protection. ... occurs before any Cygwin code ran. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Linux build in Windows
    ... ">> The solution shown above will run (under Cygwin) on the MS-Windows box! ... "> script are Windows programs. ... Is it possible to run such commands from ...
    (comp.os.linux.misc)
  • RE: Search NTFS share permissions
    ... This may get a little tricky with free software, but if you're script savvy, ... I personally use cygwin along with ... Subject: Search NTFS share permissions ...
    (Focus-Microsoft)
  • Re: OCIEnvNlsCreate error with DBD::Oracle 1.21 and Oracle 10g client in Cygwin
    ... I am able to connect to all databases from the cygwin prompt, but am unable to get the script to connect. ... I have all the below-mentioned environment variables set in the Windows environment as well, which cygwin picks up at start-up as well. ... I have tried all variations of the DBI->connect statement mentioned in the perldocs in the script below, but continue to encounter the OCIEnvNlsCreate error. ... Subject: OCIEnvNlsCreate error with DBD::Oracle 1.21 and Oracle 10g client in Cygwin ...
    (perl.dbi.users)