Win32::API::Callback - Callback support for Win32::API
use Win32::API; use Win32::API::Callback; my $callback = Win32::API::Callback->new( sub { my($a, $b) = @_; return $a+$b; }, "NN", "N", ); Win32::API->Import( 'mydll', 'two_integers_cb', 'KNN', 'N', ); $sum = two_integers_cb( $callback, 3, 2 );
Support for this module is highly experimental at this point.
I won't be surprised if it doesn't work for you.
Feedback is very appreciated.
Documentation is in the work. Either see the SYNOPSIS above or the samples in the samples or the tests in the t directory.
Win32::API::Callback uses a subset of the type letters of Win32::API. C Prototype interface isn't supported. Not all the type letters of Win32::API are supported in Win32::API::Callback.
I
i
N
n
Q
q
0x8000000050000000
"\x00\x00\x00\x50\x00\x00\x00\x80"
F
D
Unimplemented types
$numeric_char = $_[2] & 0xFF;
$numeric_char = $_[2] & 0xFFFF;
$CallbackObj = Win32::API::Callback->new( sub { print "hello world";}, 'NDF', 'Q', '__cdecl'); $CallbackObj = Win32::API::Callback->new( sub { print "hello world";}, $in, $out);
Creates and returns a new Win32::API::Callback object. Calling convention parameter is optional. Calling convention parameter has same behaviour as Win32::API's calling convention parameter. C prototype parsing of Win32::API is not available with Win32::API::Callback. If the C caller assumes the callback has vararg parameters, and the platform is 64 bits/x64, in the first 4 parameters, if they are floats or doubles they will be garbage. Note there is no way to create a Win32::API::Callback callback with a vararg prototype. A workaround is to put "enough" Ns as the in types, and stop looking at the @_ slices in your Perl sub callback after a certain count. Usually the first parameter will somehow indicate how many additional stack parameters you are receiving. The Ns in @_ will eventually become garbage, technically they are the return address, saved registers, and C stack allocated variables of the caller. They are effectivly garbage for your vararg callback. All vararg callbacks on 32 bits must supply a calling convention, and it must be '__cdecl' or 'WINAPIV'.
See "UseMI64" in Win32::API.
Callback is safe across a Win32 psuedo-fork. Callback is not safe across a Cygwin fork. On Cygwin, in the child process of the fork, a Segmentation Fault will happen if the Win32::API::Callback callback is is called.
Win32::API::Callback::IATPatch
Aldo Calpini ( dada@perl.it ). Daniel Dragan ( bulkdd@cpan.org ).
Cosimo Streppone ( cosimo@cpan.org ).
To install Win32::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::API
CPAN shell
perl -MCPAN -e shell install Win32::API
For more information on module installation, please visit the detailed CPAN module installation guide.