FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DLL32 definition with double parameter type
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 01:00 PM

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.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 01:06 PM
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
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 03:29 PM

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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 05:59 PM
So, let's assume that the doubles are in Microsoft format (can we?). You have to assign this way:

Code (fw): Select all Collapse
IMPORTO = L2BIN( NDBL2FLT( 0 ) )


EMG
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Tue Dec 19, 2017 08:19 AM
Hi Enrico.
With this code I have this result :

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

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Tue Dec 19, 2017 09:40 AM
Now you have to convert back from binary to numeric value. Use this function:

Code (fw): Select all Collapse
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
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Tue Dec 19, 2017 12:09 PM
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))

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Tue Dec 19, 2017 12:49 PM

Probably the DLL function doesn't use the Microsoft format.

EMG

Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Tue Dec 19, 2017 04:17 PM

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

Continue the discussion