perls_of_joy has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks I've been trying to write a user defined dll in C so that I can call the functions contained within the dll in my Perl program. I have used Win32::API with little trouble on existing Windows functions such as FindWindow or SendMessage, but I cannot get any basic C function to call correctly when I create the dll myself. I get a GPF every time when I attempt to call it thus: -

(From the event log)

Faulting application perl.exe, version 5.8.7.815, faulting module perl58.dll, version 5.8.7.815, fault address 0x000606b7.

I'm using Windows XP Pro sp2 with ActiveState Perl 5.8.7.
The dll is created using Visual Studio 6 sp6.

My code snippet:

The function simply takes an integer and returns it, simple as that (you would think).

use strict;<br> use diagnostics;<br><br> use Win32::API;<br><br> my $func = Win32::API->new ('C:\func.dll', 'myFunc',['I'], ['I']) or d +ie "Can't make a Win32::API object!";<br><br> print "ReturnCode = ", $func->Call(100);<br>


------ Any help with this will be greatly appreciated.

Regards

Ant

Edit: g0n closed code tag

Replies are listed 'Best First'.
Re: Help in compiling a C dll for use with Perl
by samtregar (Abbot) on Jan 31, 2006 at 17:53 UTC
    Have you looked at Inline::C? If you have a working C compiler (which seems likely) it may provide an easier path than Win32::API. Inline::C will handle compiling your C code and making it available from Perl. All you have to do is write the code and configure Inline::C to access your compiler.

    -sam

Re: Help in compiling a C dll for use with Perl
by syphilis (Archbishop) on Feb 01, 2006 at 06:23 UTC
    I second samtregar's suggestion.
    However, to address the specific issue you raised, try compiling the dll using the __stdcall calling convention. I think that's as simple as using the '/Gz' switch if you're compiling from the command line. (I'm sure the same option is readily available if you're compiling using the IDE.)

    If that doesn't help, then we might need to see the source code for the dll, and details of how you built it.

    Cheers,
    Rob