Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting a String to a Double
Message
From
20/10/1998 22:09:41
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00148663
Message ID:
00148748
Views:
20
The fastest solution I know:

Put the following function into a C DLL:
extern "C" void __declspec( dllexport ) 
StringToDouble(LPCSTR tpszDouble, double* tpnDouble)
{
	//-- lpnDouble points to the same memory as tpszDouble
	double* lpnDouble = (double*)tpszDouble;
	//-- Copy the value from lpnDouble to the return param
	*tpnDouble = *lpnDouble;
	return;
}

extern "C" void __declspec( dllexport ) 
DoubleToString(double tnDouble, LPSTR tpszDouble)
{
	//-- lpszDouble points to the same memory as tnDouble
	LPSTR lpszDouble = (LPSTR)&tnDouble;
	//-- Copy the value from lpszDouble to the return param
	memcpy(tpszDouble, lpszDouble, 8);
	//-- Apend a null char to the return param
	//   (just to be sure it's ok) 
	tpszDouble[8] = '\0';
	return;
}

The declaration in VFP will be:

DECLARE StringToDouble IN ;
	MyDll.dll ;
	STRING@, DOUBLE@
	
DECLARE DoubleToString IN ;
	MyDll.dll ;
	DOUBLE, STRING@

And use them:
*-- lcDouble must have 8 (the length of DOUBLE) + 1 bytes
lcDouble = REPLICATE(chr(0), 9)
lnDoubleIn = 123.45
lnDoubleOut = 0

= DoubleToString(lnDoubleIn, @lcDouble)
= StringToDouble(@lcDouble, @lnDoubleOut)
*-- Now, lnDoubleOut equals lnDoubleIn
Obviously, the purpose of DoubleToString is testing only.

Vlad

>I am converting a VB interface to a DLL to a VFP interface.
>
>I have a VB type def:
>
>Type AL_GRAIN
> grain_id As Integer
> grain_name As String * 32
> lbs_per_bu As Integer
> dry_mc As Double
> spare(0 To 15) As Byte
>End Type
>
>and a function declaration:
>
>Declare Function get_al_grain Lib "aglead32.dll" (ByVal c As Long, _
> ByVal n As Long, _
> ByRef g As AL_GRAIN) As Long
>
>I can get AL_GRAIN into a string but,
>
>Can anyone tell me how to convert the dry_mc to a Double in VFP?
>
>Thanks.
Previous
Reply
Map
View

Click here to load this message in the networking platform