|
From: <eg...@of...> - 2001-01-07 19:31:26
|
On Sun, Jan 07, 2001 at 02:04:01PM -0500, Soren Andersen wrote: > I am trying to compile the Perl 5 module Win32::API > (http://dada.perl.it/) on WinNT4 sp6 using MinGW - gcc-2.95.2 and > having a rough go of it with the xs code. The compilation fails > because this code has an undeclared identifier: OK, now I understand. :) This is actually a somewhat valid use of inline assembler. The deal is that this module's purpose is to call arbitrary Win32 functions with a programmatically constructed argument list. The core of the module is simply a loop which walks an array of parameters and uses _asm { push ... } to put arguments on the stack before calling the API function in question. The AbstractCallback() snippet that had us so mystified is actually a stub. It looks like the implementor never got around to callback support (which would be pretty tricky, given that the callback could have an arbitrary signature), so instead they just have a function which prints out some random value (which might be useful, given the calling conventions) and returns (possibly to crash, but you're not supposed to use it anyway). There might as well have been "assert(false)" in there, except that <prejudice> Perl hackers don't believe in reliability </prejudice>. It should be possible to port this code, though it would take someone who is pretty wizzy with GCC asm() and Win32 calling conventions. It may be that something similar happens in the guts of w32api -- I've never looked there. The biggest issue is making sure that the stack frame you're building isn't clobbered halfway through by GCC; I'd recommend refactoring the code to construct the entire frame in a char[] buffer in C, then entering one final asm() statement to adjust the stack pointer, call the actual function, and clean up. The entire module is < 400 lines of code, though, so we're not talking about heroic effort here. Dan |