On 16/06/2003 22:57:22 perl-win32-users-admin wrote: >I am having trouble with API, similar to these posts: >http://aspn.activestate.com/ASPN/Mail/Message/732561 >http://aspn.activestate.com/ASPN/Mail/Message/perl-win32-users/753232 >Like those posts, I had API working. When I tried the API scrip many months >later (during which time I had upgraded to Perl 5.6.1) I found that it did >not work. After many tests I discovered that Perl would crash if: >1. _I_ wrote the dll, and >2. The dll function expected parameters. >I found that I could call _Microsoft_ dlls with parameters, but my own dlls >crashed Perl (even though they worked correctly when called from 'C'). In [snip] > >The crash (Unhandled exception) happens after the dll successfully completes >its GiveString function. (I don't have the Perl source so I couldn't debug >into Perl.) > >The Perl code is: >chdir 'D:\DLL\Debug'; >$function = new Win32::API('dllTest1', 'GiveString', [P], V); >if (! defined $function) { >die "Could not import GiveString\n"; >} else { >$function->Call("Test string"); >} > >The C code is: >extern "C" __declspec(dllexport) >void GiveString(char* string) >{ ; } // (Guts removed for simplification) > >Any help would be greatly appreciated. >
I think the problem is that GiveString is declared "C". Most Windows API functions use the __stdcall convention; I suspect Win32::API to follow that calling convention by default at least. With the "C" calling convention, the caller cleans up the stack after the callee returns. With the __stdcall convention it is the callee's responsibility to remove the passed-in parameters (in that respect __stdcall is like the Pascal calling convention). Now you can imagine that if the calling conventions don't match, the stack is going to be mangled and soon afterwards a bogus value will be used as a subroutine return address. (If there are no parameters then it works because there is no mismatch). Try making all your functions __stdcall instead of "C". HTH, -- Csaba Ráduly, Software Engineer, Sophos Anti-Virus Email: [EMAIL PROTECTED], Tel: 01235 559933, Web: www.sophos.com Add live virus info to your website: http://www.sophos.com/link/vfeed _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs