Perl スクリプト
use Win32::API;
use Win32::API::Callback;
my $callback = Win32::API::Callback->new(Perl_Func,"PN", "N");
#Import 'C_Func' Function from dll
my $test = Win32::API->new('dll_test','C_Func','KP','N');
my $buf = pack('i*', (1, 2, 3));
#Calling the C dll Function 'C_Func' with arguments as pointer to 'Perl_Func' and integer array
my $ret = $test->Call( $callback, $buf);
print "final value=".$ret."\n";
「Perl_Func」の定義
sub Perl_Func
{
($a,$b)=@_;
print "entered into Perl Function"."\n";
print "int variable from dll=".$b."\n";
print "array first element from dll=".$a[0]."\n"; **#unable to access the value**
$res=$a[0]+$a[1]+$a[2]; **# unable to access the values here**
return $res;
}
C Dll "dll_test"
int __stdcall C_Func( int (*PerlExpFunc)( int *, int ), int *d)
{
int res,c[3];
c[0]=d[0]; c[1]=d[1]; c[2]=d[2];
res=PerlExpFunc(c,10);
return(res);
}
ここで出力は次のようになります
Perl関数に入った dll=10 からの int 変数 dll の配列の最初の要素 = 最終値=0
したがって、プログラムは dll から呼び出される 'Perl_Func' に入ります。しかし、この関数内では、dll からポインター ( c
dll および$a
'Perl_Func' の変数) として渡された配列の値にアクセスできません。したがって、値は表示されず$a[0]
、最終値、つまり 1、2、および 3 の合計はゼロになります。Cセクションから渡されたポインターから配列への値を、Perlセクションで正しく抽出していないと思います。そのための適切な方法を教えてください。