in reply to How to use Win32::API to access variable in DLL file?
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:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to use Win32::API to access variable in DLL file?
by dasgar (Priest) on Jun 23, 2009 at 19:12 UTC | |
by BrowserUk (Patriarch) on Jun 23, 2009 at 20:07 UTC | |
by dasgar (Priest) on Jun 29, 2009 at 15:06 UTC |