DLL32 definition with double parameter type

DLL32 definition with double parameter type

Postby Massimo Linossi » Sun Dec 17, 2017 3: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
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby cnavarro » Sun Dec 17, 2017 3:43 pm

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


You are tried?

Code: Select all  Expand view  RUN

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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DLL32 definition with double parameter type

Postby Massimo Linossi » Sun Dec 17, 2017 3:58 pm

Hi.
I receive an error.
5021 : The pointer given was not valid.
Thanks a lot for your suggestion.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy


Re: DLL32 definition with double parameter type

Postby Massimo Linossi » Sun Dec 17, 2017 6: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
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby Enrico Maria Giordano » Sun Dec 17, 2017 7:07 pm

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

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

Re: DLL32 definition with double parameter type

Postby Massimo Linossi » Sun Dec 17, 2017 7:13 pm

I've tried but with LPSTR the return of the function call is
always 5021 : The pointer given was not valid.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby cnavarro » Sun Dec 17, 2017 7: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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DLL32 definition with double parameter type

Postby Massimo Linossi » Sun Dec 17, 2017 7:50 pm

Hi.
Now I have a compiler error :

main.prg(463) Warning W0001 Ambiguous reference: 'LONGLONG'
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby Enrico Maria Giordano » Sun Dec 17, 2017 9: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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLL32 definition with double parameter type

Postby Massimo Linossi » Mon Dec 18, 2017 8:07 am

Hi Enrico.
Here is the code. Thanks a lot for your time.

Code: Select all  Expand view  RUN

#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"

 
Last edited by Massimo Linossi on Mon Dec 18, 2017 9:52 am, edited 1 time in total.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby Enrico Maria Giordano » Mon Dec 18, 2017 9:31 am

The error is here:

Code: Select all  Expand view  RUN
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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: DLL32 definition with double parameter type

Postby Massimo Linossi » 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))
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: DLL32 definition with double parameter type

Postby jair » 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: Select all  Expand view  RUN

     
 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.
jair
 
Posts: 57
Joined: Sun Aug 27, 2017 7:18 pm

Re: DLL32 definition with double parameter type

Postby Enrico Maria Giordano » 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: Select all  Expand view  RUN
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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests