The following uses an example which Brian once posted showing how to have a
C function call a Perl one. It actually compiles and executes on my NT4
computer, whereas the current v0.31 "Calling Perl from C" example in the
C-Cookbook fails with the following:
main_C_C__TEMP_cperl_pl_4b44facf38905876f83a09d013f9a6ec.xs(11) : error
C2371: 'c_func_2' : redefinition; different basic types
Once again, I'm failing around like a fish on dry land. Or like a Perl coder
in C. Would someone using Inline on Win32 please take the time to try out
the following code both with and without comments? I'm sure there are
obvious errors which anyone could point out.
I am trying to EnumChildWindows where a Perl subroutine will get called as
the EnumChildProc.
Please help... I am working through the K&R book once again, so I promise I
won't remain an ignoramous forever.
Garrett
use Inline C => DATA => LIBS => '-luser32';
sub foo {
print "Hello! Foo called from C land\n";
print "I got the following arguments: \n";
for (@_) {
print $_, "\n";
}
}
set_callback("main::foo");
call_callback();
// Enum_Child_Windows(0, 1);
__END__
__C__
#include <stdio.h>
#include <windows.h>
static char* callback;
void set_callback(char* name) {
callback = name;
}
void call_callback() {
Inline_Stack_Vars;
I32 flags = 0;
printf("Hello from C land\n");
Inline_Stack_Reset;
Inline_Stack_Push(newSVpvf("Apple"));
Inline_Stack_Push(newSVpvf("Orange"));
Inline_Stack_Push(newSVpvf("Neil"));
Inline_Stack_Done;
perl_call_method(callback, flags);
Inline_Stack_Void;
}
/*
int CALLBACK Enum_Child_Proc (long hWnd, long Param) {
printf("C-Land got: %d\n", hWnd);
if (hWnd = 0) hWnd = null;
Inline_Stack_Vars;
I32 flags = 0;
Inline_Stack_Reset;
Inline_Stack_Push(newSViv(hWnd));
Inline_Stack_Push(newSViv(Param));
Inline_Stack_Done;
perl_call_method(callback, flags);
return 1;
}
int Enum_Child_Windows(long hWnd, long Param) {
while (EnumChildWindows(hWnd, Enum_Child_Proc, Param) == 1) {}
}
*/