Hi, I am trying to passing in 3 pointers to a DLL function. I have:
{
$code=1;
$len=100;
$str=" " x $len;
$function = new Win32::API(DLLNAME,'dllfunction','PPP','V');
$function->Call($code,$str,$len);
}
The DLL is defined as void dllfunction(int* a, char* str, int* len); The DLL will modify all the variables pointed by the three pointers.
However, I am segfaulting when I run this. The documentation for Win32::API specified that I should use actual variable name instead of the Perl variable references. Can anyone tell me what I am missing? Thanks.
*more information:
I added printf() in the DLL to print out the address of the three pointers, and printf in Perl to print out the reference of the three variables. And I get the following
DLL : Code = 0x10107458 Error = 0x10046b50 str = 0x10107460
Perl : Code = 0x101311b8 Error = 0x101312a8 str = 0x10131230
Any idea why the DLL is getting the wrong addresses?
****More information
After much debugging, I found out that this is happening when returning from the DLL function. I added printf("done\n"); as the very last line of this DLL function, and this does output, then the program segfaults. I guess its happening in Win32::API? Has anyone experienced this?
Also, I am able to access the initial variables of all the three variables from the DLL. So the pointer is passed correctly, but for some reason it causes a segfault when returning from the DLL. Maybe it's segfaulting when trying to copy the new data into the Perl variable?