Re: Access a perl dll's function on Win32
[email protected] ("Sisyphus")
| Newsgroups | perl.module.build,perl.xs |
|---|---|
| Message-ID | <E3188E25FE5E43F6A9CE9CE06687B146@desktop2> |
----- Original Message ----- From: "Marvin Humphrey" <[email protected]> To: <[email protected]> Cc: <[email protected]> Sent: Thursday, September 04, 2008 2:15 AM Subject: Re: Access a perl dll's function on Win32 > [reply cross-posted to Module::Build list; reply-to header set to > [email protected] ] > > On Sep 3, 2008, at 6:23 AM, Sisyphus wrote: > >> Basically, if you have a perl dll (by which I mean, eg, the Digest::SHA >> dll) and you want to directly access a function from within that dll >> using XS or Inline::C, how do you do that ? > > The brute-force way is cram function addresses through Perl variables, as > suggested at <http://www.perlmonks.org/?node_id=691174> and described in > the Time::HiRes POD documentation at > <http://perldoc.perl.org/Time/HiRes.html#C-API Yes - I've used that approach before (with the help of that very same perlmonks thread) - though only in a proof-of-concept exercise (in which I also did an XS Boot) and it works beautifully. In this particular instance, however, I was thinking more of how to access the dll's functionality *without* recompiling it to include the additional functions that would be necessary for that approach to work. (Sorry - I should have made that restriction clearer.) I think that Jan's suggestion of doing a callback is probably the sane way to go. I was thinking more in terms of accessing the dll in isolation (ie without actually loading the module - which would rule out callbacks), but in reality that's probably a silly condition to be imposing anyway. I thought it might be fun to try out Reini's idea - and I've got an Inline::C script all set to go to access a function in the Math::GMPf dll. (That dll has a function that takes no args and returns an int - which keeps things really simple for me.) Only problem is I couldn't find a way to get any useful address information at all using nm, objdump or dumpbin. I was, of course, able to get the address of _boot_Math__GMPf/boot_Math__GMPf using GetProcAddress, but that's the only address I could get hold of. No matter .... it was, after all, just something I was going to try out for the heck of it ;-) Thanks guys. Cheers, Rob