- 论坛徽章:
- 0
|
Hi All,
我遇到一个Perl调用外部DLL函数传递指针变量的问题。
我查阅到Win32::API 之中,关于调用dll 之中有指针变量的部分,- P: value is a pointer (to a string, structure, etc...) padding out the buffer string is required, buffer overflow detection is performed. Pack and unpack the data yourself. If P is a return type, only null terminated strings or NULL pointer are supported. If P is an in type, NULL is integer 0. undef, "0", and ""+0 are not integer 0, "0"+0 is integer 0.
- It is suggested to not use P as a return type and instead use N and read the memory yourself, and free the pointer if applicable. This pointer is effectively undefined after the C function returns control to Perl. The C function may not hold onto it after the C function returns control. There are exceptions where the pointer will remain valid after the C function returns control, but tread at your own risk, and at your knowledge of Perl interpreter's C internals.
复制代码 这段描述的内容我不太理解,我尝试使用以下代码将指针传递进入,Card.dll为一个外部DLL,但是无法从这个变量获得返回结果,- [code]my $cs = new Win32::API('Card', 'Card_Set', 'P', 'I');
- my $b = 1;
- my $err = $cs->Call($b);
- print $b;
复制代码 [/code]
然后我查阅到有可能是C++的指针类型与perl指针有差,perl传递的地址与进入dll以后的地址不一致,所以我无法拿到需要的结果,从以上关于指针参数描述的要求,他们建议我们自己查找内存得到结果,不知道关于这一块,大家是否有类似的经验可以帮助?我发现关于Perl的技术文章随着时间的逝去,很多服务器上的文章都在消逝,有些文章已经查不到了,虽然很有用。
谢谢各位。 |
|