I have created a very simple DLL that exports a function called inc_number(), whose function is to increment a number. I imported it into Perl and invoked it like so:
use Win32::API;
die "ack!" unless Win32::API->Import('testdll.dll', 'int inc_number(in
+t *num)');
my $num = 5;
inc_number($num);
print "Number is now $num\n";
Instead of the "Number is now 6" that I was hoping for, I got:
The instruction at 0xblahblah referenced memory at 0x00000005. The memory could not be "written".
If I change the initial value of $num to 8, then the memory address in the illegal operation changes to 0x00000008 as well.
It seems like maybe Perl isn't properly recognizing that this is a by-ref parameter, and is passing by value instead?
UPDATE
I tried using the deprecated method of importing a function where you specify the parameter types instead of giving it the C prototype. It worked! Almost. 7 becomes 8, 8 becomes 9, and 9 becomes colon. 900 becomes :00. It seems like it's just incrementing the ASCII value of the first character in the numeric representation of my value. Hmm.