通过 C++从 Perl 到任意 dll 函数调用的结构指针
我正在使用 Win32::API 调用在 DLL 中导出的任意函数,该函数接受 C++ 结构指针。
struct PluginInfo {
int nStructSize;
int nType;
int nVersion;
int nIDCode;
char szName[ 64 ];
char szVendor[ 64 ];
int nCertificate;
int nMinAmiVersion;
};
由于我们需要使用“pack”函数来构造结构并需要传递一个参数,
my $name = " " x 64;
my $vendor = " " x 64;
my $pluginInfo = pack('IIIIC64C64II',0,0,0,0,$name,$vendor,0,0);
因此它没有正确构造结构。
看来应用于 C 的长度参数会吞噬掉那么多参数。
有人可以建议一种从 Perl 构造此结构并传递到 dll 调用的最佳方法吗?
预先感谢,
纳迦基兰
I am using Win32::API to call an arbitary function exported in a DLL which accepts a C++ structure pointer.
struct PluginInfo {
int nStructSize;
int nType;
int nVersion;
int nIDCode;
char szName[ 64 ];
char szVendor[ 64 ];
int nCertificate;
int nMinAmiVersion;
};
As we need to use the "pack" function to construct the structure and need to pass an argument
my $name = " " x 64;
my $vendor = " " x 64;
my $pluginInfo = pack('IIIIC64C64II',0,0,0,0,$name,$vendor,0,0);
Its not constructing the structure properly.
It seems that length argument applied to C will gobble those many arguments.
Can some one please suggest the best way to construct this structure form Perl and passon to dll call.
Thanks in advance,
Naga Kiran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在模板中使用
Z
(NUL 填充字符串),如另外,请查看
Win32::API::Struct
,它是 Win32::API 模块的一部分。Use
Z
(NUL-padded string) in your template, as inAlso, take a look at
Win32::API::Struct
, which is part of the Win32::API module.对于任何复杂的事情,请查看 Convert::Binary::C。乍一看可能令人望而生畏,但一旦您意识到它的力量,就会大开眼界。
更新:让我添加一些信息。您需要查看 模块手册页的特定部分了解使用它的主要原因。为了方便起见,我将引用它:
为什么使用 Convert::Binary::C?
For anything complicated, check out Convert::Binary::C. It may seem daunting at first, but once you realize its power, it's an eye opener.
Update: Let me add a bit of information. You need to have a look at a specific section of the module's manpage for the prime reason to use it. I'll quote it for convenience:
Why use Convert::Binary::C?