in reply to Calling a function from an external DLL with Win32::API on windows: paranormal activity
It sounds like you completely overlooked my reply in the earlier thread and recreated it from scratch.
So I inserted my $client_id = 0 before calling the function. No good; it crashed
The function expects a pointer to a block of memory that can hold 4 bytes.
You tell Win32::API to pass a pointer to a block of memory.
You provide an integer instead of a block of memory to Win32::API.
I had to do an extra $client_id = unpack "i", $client_id; to get the value I really wanted.
I don't know why this surprises you. How do you expect Win32::API or Perl to know the buffer contains a native integer if you don't tell it.
By the way, I think "l" is more appropriate if you specify "I" to Win32::API.
I got back garbage in the $Ex, etc. variables.
The function expects a pointer to a block of memory that can hold 8 bytes. (I think it's 8. I use pack to create the right amount of memory.)
You tell Win32::API to pass a pointer to a block of memory.
You provide an floating point number instead of a block of memory to Win32::API.
It seems that it can't be a hash element, either.
Nonsense. Win32::API couldn't tell the difference between a scalar and a hash's value even if it tried.
$ perl -MDevel::Peek -e'$x="abc"; %h=(x=>"abc"); sub f { Dump($_[0]) } + f($x); f($h{x});' SV = PV(0x816a040) at 0x817bc40 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x8177bf0 "abc"\0 CUR = 3 LEN = 4 SV = PV(0x816a098) at 0x816c158 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x817d920 "abc"\0 CUR = 3 LEN = 4
|
|---|