Question

I am trying to use a Win32 dll from my perl code.

use Win32::API;
$Win32::API::DEBUG = 1;
$function = Win32::API->new(
  'mydll.dll', 'int myfunc()',
);
$return = $function->Call();

But I am getting following error:

Win32::API::new: Loading library 'mydll.dll'
(PM)parse_prototype: got PROC 'myfunc'
(PM)parse_prototype: got PARAMS ''
parse_prototype: IN=[  ]
parse_prototype: OUT='int' PACKING='i' API_TYPE=3
FAILED GetProcAddress for Proc 'myfunc': The specified procedure could not be found.
Can't call method "Call" on an undefined value at .\test_dll.pl line 6.

My dll is compiled with _cdecl calling convention. Does this make any difference? I am using active perl 5.14 on windows 7

Was it helpful?

Solution

Do you use __declspec(dllexport) to export functions from DLL? If yes, use .def file instead. Because __declspec(dllexport) will make the function name in export descriptor of DLL to have underscore precede; Or mangling function name if your function is C++.

The last time I used Win32::API, its does not support __cdecl. You should change it to __stdcall instead.

OTHER TIPS

Use StudPE, PE Explorer, or dumpbin /exports to find out the real name of the function you want to use. This way you dont care if the function is name decorated or not. You know its real name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top