----- Original Message -----
From: "Foo Ji-Haw" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, February 17, 2006 7:54 PM
Subject: Tough qn: understanding this (C) error while using inline
> Hi all,
>
> I'm trying my first hand at writing some C code to extend TAPI onto Perl
> using inline.pm. I didn't get very far though. Appreciate if anyone can
> help explain the error (source code is attached).
>
Make sure you have a good look through 'perldoc Inline::C-Cookbook'. It has
many helpful examples.
Reinhard's method of linking to the tapi32 library looks a little odd to me
... however, I can't say it doesn't work as I haven't tested it.
I usually link to libraries using the construct shown in the demo below.
There are problems with passing/returning 'DWORD' and 'HINSTANCE' types. The
script below also demonstrates those problems - along with a couple of
possible solutions. In each case a third solution is to provide a 'typemap'
file that tells perl how to deal with the 'DWORD' and 'HINSTANCE' types.
use warnings;
use Inline C => Config =>
LIBS => '-ltapi32', # not necessary for this demo
BUILD_NOISY => 1; # See the build process in progress
use Inline C => <<'EOC';
#include <windows.h> // not really necesary as it's
// already included by perl.h
// 'foo1_nok()' compiles ok but won't work without
// an appropriate typemap that tells perl how
// to deal with the 'DWORD' type argument/return.
DWORD foo1_nok(DWORD x) {
x++;
return x;
}
unsigned foo1_ok1(unsigned x) {
DWORD t;
t = (DWORD)x;
t++;
return (unsigned)t;
}
SV * foo1_ok2(SV * x) {
DWORD t;
t = (DWORD)SvUV(x);
t++;
return newSVuv((unsigned long)t);
}
// 'foo2_nok()' compiles ok but won't work without
// an appropriate typemap that tells perl how
// to deal with the 'HINSTANCE' type argument/return.
HINSTANCE foo2_nok(HINSTANCE x) {
return x;
}
int foo2_ok1(int x) {
HINSTANCE t;
t = (HINSTANCE)x;
return (int)t;
}
SV * foo2_ok2(SV * x) {
HINSTANCE t;
t = (HINSTANCE)SvIV(x);
return newSViv((int)t);
}
EOC
$a = 121;
$x = foo1_ok1($a);
$y = foo1_ok2($a);
print $x, " ", $y, "\n";
eval {
no warnings;
$z = foo1_nok($a);# Also issues a warning unless disabled
};
if($@) {print "\$\@: ",[EMAIL PROTECTED]
else {print $z, "\n"}
print "##########################\n";
$x = foo2_ok1($a);
$y = foo2_ok2($a);
print $x, " ", $y, "\n";
eval {
no warnings;
$z = foo2_nok($a);# Also issues a warning unless disabled
};
if($@) {print "\$\@: ",[EMAIL PROTECTED]
else {print $z, "\n"}
__END__
Cheers,
Rob
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs