On Wed, 03 Sep 2008, Sisyphus wrote:
> This stems from http://www.perlmonks.org/index.pl?node_id=708569 .
> 
> 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 ?
>
> With most Windows dll's, you can just use LoadLibrary() to get a handle to
> the dll, and then use GetProcAddress() to return the address of the function
> you want to access.
> 
> For the first part, there's no problem  - one can easily use LoadLibrary()
> to return a handle to SHA.dll. It's the second part that presents the
> problem. GetProcAddress() can only return the address of functions/variables
> that are *exported* ... and most of the functions in SHA.dll (eg 'hashsize')
> are *not* exported.
> 
> How, therefore, can I get at the 'hashsize' function from an Inline::C
> script (or an XSub) on Win32 ?

As the thread on PerlMonks already states, you call it using
perl_call_pv() because the XS function already expects to be called
using Perl calling conventions:

    count = perl_call_pv("Digest::SHA::hashsize", G_SCALAR|G_EVAL);

If you want to call a C-level function directly using GetProcAddress()
then you must make sure that the module explicitly exports that symbol.
I've done this in Win32::OLE for some functions that are explicitly used
by some applications hosting a Perl interpreter. Look at the Makefile.PL
to see how to do it on Win32:

    http://search.cpan.org/src/JDB/Win32-OLE-0.1709/Makefile.PL

I cannot remember why I also had to add the MY::dlsyms() function;
ideally adding the FUNCLIST argument to WriteMakefile() should be
enough, but I guess it wasn't when I wrote that code (about 10 years
ago, but it still works with current Perl and EU::MM).

Cheers,
-Jan


Reply via email to