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
DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 03:23 PM
Hi.
It is possible to define a double type parameter in the DLL32 definition ?
I have this function to call for retrieving a Double field into an Advantage Database table.

DLL32 Function AdsGetDouble (phTable AS LONG, pucFldName AS LPSTR, @pdValue AS LONG) ;
AS LONG PASCAL FROM "AdsGetDouble" LIB "ACE32.DLL"

The pdValue is a Double field. With the LONG definition I'm losing the decimals.

Thanks a lot.
Massimo
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 03:43 PM

DLL32 Function AdsGetDouble (phTable AS LONG, pucFldName AS LPSTR, @pdValue AS LONG)


You are tried?

Code (fw): Select all Collapse
DLL32 Function AdsGetDouble (phTable AS LONG, pucFldName AS LPSTR, @pdValue AS _DOUBLE )
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 03:58 PM

Hi.
I receive an error.
5021 : The pointer given was not valid.
Thanks a lot for your suggestion.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 06:36 PM

Try using AS PTR.

EMG

Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 06:52 PM

Hi.
Now there is no error but I get a strange result.
Inside the table field the value is 729.29 but with this code I get -343597384

value = 0.00
AdsGetDouble(handle, "IMPORTO", @value)
msginfo(value)

Many thanks for your help.
Massimo

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 07:07 PM

So you have to use AS LPSTR and convert the content of the string to the required value.

EMG

Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 07:13 PM

I've tried but with LPSTR the return of the function call is
always 5021 : The pointer given was not valid.

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 07:41 PM
Massimo Linossi wrote:Hi.
It is possible to define a double type parameter in the DLL32 definition ?
I have this function to call for retrieving a Double field into an Advantage Database table.

DLL32 Function AdsGetDouble (phTable AS LONG, pucFldName AS LPSTR, @pdValue AS LONG) ;
AS LONG PASCAL FROM "AdsGetDouble" LIB "ACE32.DLL"

The pdValue is a Double field. With the LONG definition I'm losing the decimals.

Thanks a lot.
Massimo


Please, Can you try with?


DLL32 Function AdsGetDouble (phTable AS LONG, pucFldName AS LPSTR, @pdValue AS LONGLONG) ;
AS LONG PASCAL FROM "AdsGetDouble" LIB "ACE32.DLL"
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 07:50 PM

Hi.
Now I have a compiler error :

main.prg(463) Warning W0001 Ambiguous reference: 'LONGLONG'

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Sun Dec 17, 2017 09:35 PM
Massimo Linossi wrote:I've tried but with LPSTR the return of the function call is
always 5021 : The pointer given was not valid.


Can I see the complete sample, please?

EMG
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 08:07 AM
Hi Enrico.
Here is the code. Thanks a lot for your time.

Code (fw): Select all Collapse
#include "fivewin.ch"
#include "c:\xHb\include\ads.ch"

STATIC Ads_Handle, nreturn, handle, handle_index, stringa, stringaUTF, finefile

PROCEDURE Main
LOCAL importo_tot
LOCAL ora_inizio, ora_fine

local aFields:={} , aFile:="C:\TEMP\TEST", bFile:="C:\TEMP\CONTEGGI", contatore:=0
local ora_inizio, ora_fine
LOCAL pucBuf
LOCAL pucBufLen
LOCAL handle, handle_index, tot_records, conta_records
LOCAL COD_UTENTE, IMPORTO

SET DELETED ON
SET CENTURY ON
SET CONFIRM ON
SET DATE BRITISH
SET _3DLOOK ON
SET EPOCH TO 1990
SET EXCLUSIVE OFF

REQUEST HB_LANG_IT
HB_LANGSELECT("IT")
REQUEST ADS
REQUEST RMDBFCDX
REQUEST DBFFPT
rddRegister( "ADS", 1 )
rddsetdefault( "ADS" )

SET SERVER REMOTE

SET FILETYPE TO ADT
SET(_SET_AUTORDER,1)
SET AUTOPEN ON
set(_SET_OPTIMIZE,.F.)
ADSLOCKING(.F.)
eval({||sethandlecount( 120 )})

IF !AdsConnect60("C:\ARCHIVI\DATABASE.ADD", 7, "login", "password", , @Ads_Handle)
聽 聽 MsgStop("Il database non 猫 connesso." , "Attenzione")
聽 聽 Return
ENDIF
AdsConnection(Ads_Handle)

ora_inizio = time()

aadd(aFields, 聽{ "COD_UTENTE" , "C" , 10 聽, 0 })
aadd(aFields, 聽{ "TOTALE" 聽 聽 聽 聽 聽, "N" , 12 聽, 2 })

Ferase(afile + ".DBF")
DbCreate( afile , aFields , "RMDBFCDX" )

USE (aFile) ALIAS APPO 聽 聽 聽 聽 EXCLUSIVE NEW 聽 聽 聽 聽 聽VIA "RMDBFCDX"
USE (bFile) ALIAS CONTEGGI SHARED 聽 聽NEW READONLY VIA "RMDBFCDX"

AdsOpenTable90(Ads_Handle, "IMPORTI", "IMPORTI", 0, 1, 0, 1, 2, ,@handle )
AdsGetIndexHandle(handle, "COD_UTENTE", @handle_index )

sele conteggi
Dbgotop()
Do While !eof()
聽 聽 importo_tot = 0

聽 聽 AdsClearScope(handle_index, 1)
聽 聽 AdsClearScope(handle_index, 2)
聽 聽 AdsSetScope(handle_index, 1, conteggi->COD_UTENTE, 10, 2)
聽 聽 AdsSetScope(handle_index, 2, conteggi->COD_UTENTE, 10, 2)
聽 聽 AdsGotoTop(handle_index)
聽 聽 AdsGetRecordCount(handle_index, 3, @tot_records)

聽 聽 conta_records = 0
聽 聽 do while .t.
聽 聽 聽 聽 IMPORTO 聽= 0.00
聽 聽 聽 聽 nReturn = AdsGetDouble(handle, "IMPORTO", @IMPORTO)
聽 聽 聽 聽 *
聽 聽 聽 聽 * 聽 聽here nReturn = 5021 ; the pointer given was not valid
聽 聽 聽 聽 * 聽 聽 聽 聽 importo = 0


聽 聽 聽 聽 importo_tot += round(IMPORTO,2)
聽 聽 聽 聽 AdsSkip(handle, 1)
聽 聽 聽 聽 conta_records ++
聽 聽 聽 聽 if conta_records > tot_records
聽 聽 聽 聽 聽 聽 exit
聽 聽 聽 聽 endif
聽 聽 enddo

聽 聽 contatore ++

聽 聽 Select Appo
聽 聽 DbAppend()
聽 聽 Appo->COD_UTENTE 聽= conteggi->COD_UTENTE
聽 聽 Appo->TOTALE 聽 聽 聽= importo_tot

聽 聽 Select conteggi
聽 聽 DbSkip()
Enddo
AdsCloseindex(handle_index)
AdsCloseTable(handle)

ora_fine = time()

Dbcloseall()
MSGINFO(ora_inizio + " 聽 " + ora_fine,str(contatore))

AdsDisconnect(Ads_Handle)
AdsApplicationExit()
quit

Return

DLL32 Function Type_AdsGetConnection(adshandle as LONG) ;
AS LONG PASCAL FROM "AdsGetConnectionType" LIB "ACE32.DLL"

DLL32 Function Create_sql(hConnect as LONG, @phStatement as LONG) ;
AS LONG PASCAL FROM "AdsCreateSQLStatement" LIB "ACE32.DLL"

DLL32 Function Close_sql(hStatement as LONG) ;
AS LONG PASCAL FROM "AdsCloseSQLStatement" LIB "ACE32.DLL"

DLL32 Function ADS_DateFormat(stringa_test As LPSTR, @adshandle as LONG) ;
AS LONG PASCAL FROM "AdsGetDateFormat" LIB "ACE32.DLL"

DLL32 Function Verify_Ads(hStatement as LONG, @pucSQL As LPSTR) ;
AS LONG PASCAL FROM "AdsVerifySQL" LIB "ACE32.DLL"

DLL32 Function Error_Ads(@pulErrorCode As LONG, @pucBuf As LPSTR, @pucBufLen As LONG) ;
AS LONG PASCAL FROM "AdsGetLastError" LIB "ACE32.DLL"

DLL32 Function AdsOpenTable(hConnect AS LONG, pucName AS LPSTR, pucAlias AS LPSTR, usTableType AS LONG, usCharType AS LONG, usLockType AS LONG, usCheckRights AS LONG, ulOptions AS LONG, @phTable AS LONG) ;
AS LONG PASCAL FROM "AdsOpenTable" LIB "ACE32.DLL"

DLL32 Function AdsOpenTable90(hConnect AS LONG, pucName AS LPSTR, pucAlias AS LPSTR, usTableType AS LONG, usCharType AS LONG, usLockType AS LONG, usCheckRights AS LONG, ulOptions AS LONG, pucCollation as LONG, @phTable AS LONG) ;
AS LONG PASCAL FROM "AdsOpenTable90" LIB "ACE32.DLL"

DLL32 Function AdsOpenIndex(hTable AS LONG, pucName AS LPSTR, @ahIndex AS LPSTR, @pusArrayLen AS LPSTR ) ;
AS LONG PASCAL FROM "AdsOpenIndex" LIB "ACE32.DLL"

DLL32 Function AdsGetAllIndexes(hTable AS LONG, @ahIndex AS LPSTR, pusArrayLen AS LPSTR ) ;
AS LONG PASCAL FROM "AdsGetAllIndexes" LIB "ACE32.DLL"

DLL32 Function AdsGetIndexHandle(hTable AS LONG, pucIndexOrder AS LPSTR, @phIndex AS LONG ) ;
AS LONG PASCAL FROM "AdsGetIndexHandle" LIB "ACE32.DLL"

DLL32 Function AdsSetScope(hIndex AS LONG, usScopeOption AS LONG, @pucScope AS LPSTR, usScopeLen AS LONG, usDataType AS LONG ) ;
AS LONG PASCAL FROM "AdsSetScope" LIB "ACE32.DLL"

DLL32 Function AdsClearScope(hIndex AS LONG, usScopeOption AS LONG ) ;
AS LONG PASCAL FROM "AdsClearScope" LIB "ACE32.DLL"

DLL32 Function AdsGetRecordCount(hObj AS LONG, usFilterOption AS LONG, @pulCount AS LONG ) ;
AS LONG PASCAL FROM "AdsGetRecordCount" LIB "ACE32.DLL"

DLL32 Function AdsGoTop (phTable 聽AS LONG) ;
AS LONG PASCAL FROM "AdsGoTop" LIB "ACE32.DLL"

DLL32 Function AdsGotoTop (phTable 聽AS LONG) ;
AS LONG PASCAL FROM "AdsGotoTop" LIB "ACE32.DLL"

DLL32 Function AdsGotoRecord (phTable AS LONG, ulRec AS LONG) ;
AS LONG PASCAL FROM "AdsGotoRecord" LIB "ACE32.DLL"

DLL32 Function AdsSkip (phTable AS LONG, ulRec AS LONG) ;
AS LONG PASCAL FROM "AdsSkip" LIB "ACE32.DLL"

DLL32 Function AdsGetField (hTable AS LONG, pucFldName AS LPSTR, @pucBuf AS LPSTR, pulLen AS LONG, usOption AS LONG) ;
AS LONG PASCAL FROM "AdsGetField" LIB "ACE32.DLL"

DLL32 Function AdsGetFieldW (hTable AS LONG, pucFldName AS LPSTR, @pwcBuf AS LPSTR, pulLen AS LONG, usOption AS LONG) ;
AS LONG PASCAL FROM "AdsGetFieldW" LIB "ACE32.DLL"

DLL32 Function AdsGetLong (hTable 聽AS LONG, pucFldName AS LPSTR, @plValue AS LONG) ;
AS LONG PASCAL FROM "AdsGetLong" LIB "ACE32.DLL"

DLL32 Function AdsGetDouble (hTable AS LONG, pucFldName AS LPSTR, @pdValue AS LPSTR) ;
AS LONG PASCAL FROM "AdsGetDouble" LIB "ACE32.DLL"

DLL32 Function AdsGetRecord (hTable 聽AS LONG, @pucRec AS LPSTR, @pucLen AS LONG) ;
AS LONG PASCAL FROM "AdsGetRecord" LIB "ACE32.DLL"

DLL32 Function AdsGetRecordLength (hTable 聽AS LONG, @pucLen AS LONG) ;
AS LONG PASCAL FROM "AdsGetRecordLength" LIB "ACE32.DLL"

DLL32 Function AdsCacheRecords (phTable 聽AS LONG, @usRecords AS LONG) ;
AS LONG PASCAL FROM "AdsCacheRecords" LIB "ACE32.DLL"

DLL32 Function AdsAtEOF (phTable AS LONG, @pbEof AS LONG) ;
AS LONG PASCAL FROM "AdsAtEOF" LIB "ACE32.DLL"

DLL32 Function AdsGetString (phTable 聽AS LONG, pucFldName AS LPSTR, @pucbuf AS LPSTR, @pwcbuf AS LPSTR, pulLen AS LONG, usOption as LONG ) ;
AS LONG PASCAL FROM "AdsGetString" LIB "ACE32.DLL"

DLL32 Function AdsCloseTable (phTable 聽AS LONG) ;
AS LONG PASCAL FROM "AdsCloseTable" LIB "ACE32.DLL"

DLL32 Function AdsCloseIndex (phTable 聽AS LONG) ;
AS LONG PASCAL FROM "AdsCloseIndex" LIB "ACE32.DLL"
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 09:31 AM
The error is here:

Code (fw): Select all Collapse
IMPORTO  = 0.00


You have to make a string buffer of the right length for a double and then store in it the binary value for 0.00.

EMG
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 11:10 AM

Hi Enrico.
With this code nReturn is 0 (correct) but IMPORTO is -343597384

IMPORTO = "0.00"
nReturn = AdsGetDouble(handle, "IMP_FORN", @IMPORTO)
msginfo(IMPORTO, str(nReturn))

Posts: 74
Joined: Sun Aug 27, 2017 07:18 PM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 11:18 AM
Tengo una DLL escrita en c # y tengo un ejemplo de consumir esta funci贸n que esta en la DLL de C # en Delphi, ahora prefiero consumir esta misma funci贸n en xHarbour, alguien podr铆a ayudarme.

Code (fw): Select all Collapse
 
聽 聽 聽
聽Ret := TCertfly.Assinar('C:\xml\R1000_N.xml', 聽 'C:\xml\R1000_ASS.xml', 聽'MinhaTag','0', '1ce63d4dcefb45e9', '1234');

聽 聽 聽if Ret = 0 then
聽 聽 聽 聽ShowMessage('Sucesso')
聽 聽 聽else
聽 聽 聽 聽ShowMessage('False');
聽 聽 end;
聽 聽 聽
聽 聽 end.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: DLL32 definition with double parameter type
Posted: Mon Dec 18, 2017 12:32 PM
Massimo Linossi wrote:Hi Enrico.
With this code nReturn is 0 (correct) but IMPORTO is -343597384

IMPORTO = "0.00"
nReturn = AdsGetDouble(handle, "IMP_FORN", @IMPORTO)
msginfo(IMPORTO, str(nReturn))


Code (fw): Select all Collapse
IMPORTO = "0.00"


is not correct. This is a string representing a value while you have to:

- create a string with the right length for the double value required by the function (8 bytes?)
- put in that string the binary value of 0.00, not the string value (8 CHR( 0 )s?)

EMG