Search code examples
perlwinapiactiveperl

Win32::API perl Procedure not found


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


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.