DLL32 definition with double parameter type

User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Post by Massimo Linossi »

Placing a replicate(chr(0),8) in the importo variable I have the same result.

Looking inside the ADS documentation I found this :

AdsGetLong
Retrieves the long integer value from the given field.
Syntax

UNSIGNED32
AdsGetLong (ADSHANDLE hTable,
UNSIGNED8 *pucFldName,
SIGNED32 *plValue);

Parameters
hTable (I)
Handle of table or cursor.

pucFldName (I)
Name of field to retrieve.

plValue (O)
Return the value.

Special Return Codes
AE_NO_CURRENT_RECORD

Data cannot be retrieved from EOF or BOF.

Remarks
AdsGetLong returns the signed long value stored in the numeric, integer, short integer, double, CurDouble, RowVersion, or auto-increment field. It is possible to either overflow the value or lose decimal precision by using this function. If more precision is desired, use AdsGetDouble. When using this function to retrieve an auto-increment value, be sure to treat the result as an unsigned value. If AdsGetLong is used to retrieve a Money field, the four decimal digits will be rounded to the nearest whole number.
The pucFldName parameter can be passed as the field name itself or as the one-based integer field position. To pass an integer field position for the pucFldName parameter, use the ADSFIELD macro that is defined in ACE.H. For example, to specify the first field in the table, pass ADSFIELD(1) for the pucFldName parameter; to specify the second field in the table, pass ADSFIELD(2) for the pucFldName parameter; etc.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: DLL32 definition with double parameter type

Post by Enrico Maria Giordano »

Massimo Linossi wrote:Placing a replicate(chr(0),8) in the importo variable I have the same result.
Probably it's not the right binary representation for 0 double value the function is expecting. There is any mention in the docs about the expected double format?

EMG
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Post by Massimo Linossi »

The only documentation I found is that I wrote 2 messages ago.
There is not so much about this on their forum too.
Thanks a lot.
Massimo
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: DLL32 definition with double parameter type

Post by Enrico Maria Giordano »

So, let's assume that the doubles are in Microsoft format (can we?). You have to assign this way:

Code: Select all

IMPORTO = L2BIN( NDBL2FLT( 0 ) )
EMG
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Post by Massimo Linossi »

Hi Enrico.
With this code I have this result :

IMPORTO = L2BIN( NDBL2FLT( 0 ))
nReturn = AdsGetDouble(handle, "IMPORTO", @IMPORTO)
msginfo(IMPORTO, str(nReturn))

Image
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: DLL32 definition with double parameter type

Post by Enrico Maria Giordano »

Now you have to convert back from binary to numeric value. Use this function:

Code: Select all

HB_FUNC( NFLT2DBL )
{
    float nVal;

    const char *cPar = hb_parc( 1 );
    char *cVal = ( char * ) &nVal;

    cVal[ 0 ] = cPar[ 0 ];
    cVal[ 1 ] = cPar[ 1 ];
    cVal[ 2 ] = cPar[ 2 ];
    cVal[ 3 ] = cPar[ 3 ];

    hb_retndlen( nVal, 15, 6 );
}
EMG
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Post by Massimo Linossi »

Hi.
With the function changed like this, I have this result :

IMPORTO = L2BIN( NDBL2FLT( 0 ))
nReturn = AdsGetDouble(handle, "IMPORTO", @IMPORTO)
msginfo(NFLT2DBL(IMPORTO), str(nReturn))

Image
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Post by Massimo Linossi »

You're right.
I surrender. Thanks a lot for your time.
Massimo
Post Reply