Information générale
Catégorie:
Codage, syntaxe et commandes
This is a message I posted some time ago. Replace the double with float and it should work.
Vlad
>>>
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
<<<
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement