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

Hi all, i have a dll file written in C language. i have written a C code to load the DLL file and get some information from the API. Is there a way to load this dll file using perl and get the information from the API. If yes can some one post a sample code to load the DLL , call some API and get information.
  • Comment on how to load a DLL file written in C code using PERL

Replies are listed 'Best First'.
Re: how to load a DLL file written in C code using Perl
by jettero (Monsignor) on Apr 06, 2007 at 15:11 UTC

    There are two main ways: XS and Inline::C. I'm a big fan of xs, but I believe the inline C is considered easier to learn. You'll almost certainly have to write some kind of wrapper to pull the functions up into your application — unless someone has already done the ground work.

    UPDATE: correction... three main ways. I was unaware of this Win32::API namespace. That makes everything a lot simpler I bet. I now wonder if there's such a thing for elf.so.

    -Paul

Re: how to load a DLL file written in C code using PERL
by BrowserUk (Patriarch) on Apr 06, 2007 at 15:26 UTC

    Take a look at Win32::API & Win32::API::Prototype. If you are using an Active State build you probably have the former already installed. I find the latter easier to use, but installing it isn't trivial.

    If you encounter problems, come back with what you have, and the function signatures of the APIs you are trying to access and you'll get more help.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: how to load a DLL file written in C code using PERL
by saintly (Scribe) on Apr 06, 2007 at 16:56 UTC
    There is an example of how to do this (using an XSUB) from quite a while ago: callbacks in XS code.