【问题标题】:Win32::API perl Procedure not foundWin32::API perl 程序未找到
【发布时间】:2013-07-13 13:26:36
【问题描述】:

我正在尝试使用我的 perl 代码中的 Win32 dll。

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

但我收到以下错误:

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.

我的 dll 是使用 _cdecl 调用约定编译的。这有什么区别吗? 我在 Windows 7 上使用活动 perl 5.14

【问题讨论】:

  • mydll.dll 不包含名为 myfunc 且没有返回 int 的参数的函数?

标签: perl winapi activeperl


【解决方案1】:

您是否使用__declspec(dllexport) 从 DLL 导出函数?如果是,请改用.def 文件。因为__declspec(dllexport)会使DLL的导出描述符中的函数名前有下划线;或者如果您的函数是 C++,则修改函数名称。

上次使用Win32::API,不支持__cdecl。您应该改为将其更改为 __stdcall

【讨论】:

  • 添加 __declspec(dllexport) 对我有用。返回过程引用。我改变了调用,因为它的 _cdecl 为$function = Win32::API->new( 'mydll.dll', 'myfunc', 'I', undef, '_cdecl' ); $return = $function->Call( ); 虽然脚本在调用过程时崩溃了。
【解决方案2】:

使用 StudPE、PE Explorer 或 dumpbin /exports 找出您要使用的函数的真实名称。这样你就不用关心函数是否是名称修饰的。你知道它的真名。

【讨论】:

    猜你喜欢
    • 2012-03-27
    • 1970-01-01
    • 2013-08-11
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-04-07
    相关资源
    最近更新 更多