You don't need Win32::API nor compiler, to access those values. It can all be done using Win32 that comes with AS Perl's.
Given a dll that contains this exported integer (compiled as test.dll):
__declspec(dllexport) int testint = 12345;
That might be accessed from a C program so:
#include <windows.h>
#include <stdio.h>
int main( int argc, char **argv ) {
HMODULE hm = (HMODULE)LoadLibrary( "test.dll" );
int *ptestint = (int *)GetProcAddress( hm, "testint" );
printf( "Addr: %x Value: %d\n", ptestint, *ptestint );
return 1;
}
It can be accessed from (AS) perl as follows:
#! perl -slw
use strict;
use Win32;
my $dll = Win32::LoadLibrary(
'test'
) or die $^E;
my $proc = Win32::GetProcAddress(
$dll, 'testint'
) or die $^E;
print unpack 'V', unpack 'P4', pack 'L!', $proc;
__END__
C:\test>\perl32\bin\perl.exe 773754.pl
12345
The complicated bit is the last line:
- pack 'L!', $proc converts the UV returned by GetProcAddress() back into a binary value;
- unpack 'P4', ... fetches 4-bytes (the exported integer) from that address;
- unpack 'V', ... converts those 4-bytes into a perl scalar;
Assuming that your running on a platform where int and long and synonymous, that should work for all three values. Otherwise you'll need to adjust the 'V' for the last one.
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.