Apparent bug in Win32::API if function returns a float or a double
- From: "Trevor Magnusson" <trevor.magnusson@xxxxxxxxxxxxxx>
- Date: Thu, 22 May 2008 14:05:34 +1000
Summary: there appears to be a bug with the perl module Win32::API, calling
functions that return a float or a double.
*** I have eliminated the "stdcall v cdecl" newby-trap as an explanation!
***
I have tested the problem under two environments:
A fresh install of ActivePerl-5.10.0.1003-MSWin32-x86-285500.msi
* Install folder changed from default to C:\Perl510
* This build includes Win32::API v0.55
* No further modules were installed
* I modified my command-prompt environment as follows:
set
PERL5LIB=C:\Perl510;C:\Perl510\bin;C:\Perl510\site;C:\Perl510\site\lib
set
PERLLIB=C:\Perl510;C:\Perl510\bin;C:\Perl510\site;C:\Perl510\site\lib
PATH C:\Perl510\bin;c:\windows;c:\windows\system32
A fresh install of ActivePerl-5.8.8.822-MSWin32-x86-280952.msi
* Install folder changed from default to C:\Perl58
* From the C:\Perl58\bin folder I performed the following, which installed
Win32::API v 0.53
ppm.bat install Win32-API
* I modified my command-prompt environment as follows:
set PERL5LIB=C:\Perl58;C:\Perl58\bin;C:\Perl58\site;C:\Perl58\site\lib
set PERLLIB=C:\Perl58;C:\Perl58\bin;C:\Perl58\site;C:\Perl58\site\lib
PATH C:\Perl58\bin;c:\windows;c:\windows\system32
I have written a simple DLL that exports three functions:
int __stdcall MyStrToInt (char* aStr);
float __stdcall MyStrToFloat (char* aStr);
double __stdcall MyStrToDouble (char* aStr);
I have tested that DLL by calling all three functions from another
executable.
*** I have VERIFIED that the functions are exported with the "stdcall"
calling convention. ***
When I call MyStrToInt() from perl, it works correctly
When I call either MyStrToFloat() or MyStrToDouble(), the process fails. The
error dialog begins...
Perl Command Line Interpreter has encountered a
problem and needs to close. We are sorry for the
inconvenience.
I have succeeded in debugging the call to my DLL inside my IDE.
The failed function is called TWICE, which to me suggests confusion about
how many bytes are pushed or popped from the stack.
If my analysis is correct, the "RET" instruction is seeing my function's
address on the stack instead of the return address setup by the caller.
my perl script follows:
########################
use Win32::API;
#print "Press Enter\n";
#<STDIN>;
my ($dllname,$function,$return,$doubleret,$floatret);
$dllname = 'tmdll.dll';
########################
##### MyStrToInt() #####
########################
print "Calling API->new to get handle to MyStrToInt()\n";
$function = Win32::API->new($dllname, 'MyStrToInt', 'P', 'I');
print "Calling tmDLL MyStrToInt()\n";
$return = $function->Call("123");
print "HYDLL MyStrToInt() returned $return\n";
##########################
##### MyStrToFloat() #####
##########################
print "Calling API->new to get handle to MyStrToFloat()\n";
$function = Win32::API->new($dllname, 'MyStrToFloat', 'P', 'F');
print "Calling tmDLL MyStrToFloat()\n";
$floatret = $function->Call("123");
print "HYDLL MyStrToFloat() returned $floatret\n";
###########################
##### MyStrToDouble() #####
###########################
print "Calling API->new to get handle to MyStrToDouble()\n";
$function = Win32::API->new($dllname, 'MyStrToDouble', 'P', 'D');
print "Win32::API-New returned undef\n" if(!defined($function));
print "Calling tmDLL MyStrToDouble()\n";
$doubleret = $function->Call("123");
print "HYDLL MyStrToDouble() returned $doubleret\n";
.
- Follow-Ups:
- Prev by Date: Re: Writing VB macro script in xls
- Next by Date: Apparent bug in Win32::API if function returns a float or a double
- Previous by thread: Writing VB macro script in xls
- Next by thread: Re: Apparent bug in Win32::API if function returns a float or a double
- Index(es):
Relevant Pages
|
|