Dear all, I am trying to get the value of char pointer or string in the return of call() function for my dll. my dll is having a function Rando开发者_StackOverflow社区mDec(long , int*) and returns a string. so what will be my call using Win32::API(). I have tried this and didn't succeed. plz help
use Win32::API;
my @lpBuffer = " " x 20;
my $pp= \@lpBuffer;
my $xy=0;
my $ff= \$xy;
my $fun2 = new Win32::API('my.dll','RandomDec','NP','**P**')or die $^E;
$pp = $fun2->Call(4,$ff);
how to get using $pp ?
There are multiple errors in your code.
-
my @lpBuffer = " " x 20; my $pp= \@lpBuffer;
=> my $pp = " " x 20;
You are mixing arrays with strings, and you don't need a perl ref for a c ptr. Similar for the int*.
- N is for number not long. L would be unsigned, you need signed, so l.
use Win32::API; my $pp = " " x 20; # alloc a string my $xy = 0; # alloc an int my $fun2 = new Win32::API('my.dll','RandomDec','lP','P') or die $^E; $pp = $fun2->Call(4,$xy);
I haven't check if Win32::API can do lvalue assignment to char*. Normally not, so $pp will be a foreign pointer to some string after the call, and the prev. PV slot for $pp will be lost, and inaccessible from perl. With FFI's and the WinAPI also you usually return int, not strings. Strings only via sideeffects, as function arg.
精彩评论