Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stumped by a DLL
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01052286
Message ID:
01052351
Views:
15
John,

I would try to convert FoxPro numbers to floats before calling your function, and backwards on return.

In VFP9, BINTOC() and CTOBIN() will do the job. For earlier versions I have two procedures:
#DEFINE REAL_BIAS 127
#DEFINE REAL_MANTISSA_SIZE 23
#DEFINE REAL_NEGATIVE 0x80000000
#DEFINE EXPONENT_MASK 0x7F800000
#DEFINE MANTISSA_MASK 0x7FFFFF

FUNCTION Int2Float(num)
* converts FoxPro numeric to 32-bit float form, similar to BINTOC()
* use it to convert input parameters to pass to your function
	LOCAL sgn, exponent, mantissa
	DO CASE
	CASE num < 0
		sgn = REAL_NEGATIVE
		num = -num
	CASE num > 0
		sgn = 0
	OTHERWISE
		RETURN 0
	ENDCASE
	exponent = FLOOR(LOG(num)/LOG(2))
	mantissa = (num - 2^exponent)* 2^(REAL_MANTISSA_SIZE-exponent)
	exponent = BITLSHIFT(exponent+REAL_BIAS, REAL_MANTISSA_SIZE)
RETURN BITOR(sgn, exponent, mantissa)

FUNCTION Float2Int(num)
* similar to CTOBIN()
* use it to decode parameters returned by your function
	LOCAL sgn, exponent, mantissa
	sgn = IIF(BITTEST(num,31), -1,1)
	exponent = BITRSHIFT(BITAND(num, EXPONENT_MASK),;
		REAL_MANTISSA_SIZE) - REAL_BIAS
	mantissa = BITAND(num,;
		MANTISSA_MASK) / 2^(REAL_MANTISSA_SIZE-exponent)
RETURN (2^exponent + mantissa) * sgn
Then one of these two declarations, or even both, would probably work:
DECLARE integer foo IN 'foo.dll' integer @value1, integer @value2
DECLARE integer foo IN 'foo.dll' double @value1, double @value2
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform