Collegare una DLL con C Struttura

Moderator: Enrico Maria Giordano

Collegare una DLL con C Struttura

Postby a.tixi@htech.it » Tue Mar 21, 2017 4:11 pm

Salve,
Dovrei tradurre un sorgente scritto in C collegandomi ad una DLL in xHarbour e FWH 9.05. Ho usato la classe tStruct (non so se nel corso del tempo ha subito cambiamenti),
ma il risultato è che non riesco a collegarmi al device. Qualcuno mi saprebbe indicare la soluzione
Grazie

typedef struct
{
char IPAddress[16]; //xxx.xxx.xxx.xxx
int Port;
} TETHParameters;

typedef struct
{
char Amount[8+1];
char ECRId[8+1];
char PaymentType[1+1];
char TerminalId[8+1];
} TECRData;

typedef struct
{
char TerminalId[8+1];
char AcquirerId[11+1];
char TransactionType[3+1];
char TransactionResult[2+1];
} TPOSData;

TETHParameters ETHParameters;
strcpy(ETHParameters.IPAddress, “192.168.1.2”);
ETHParameters.Port = 1234;
IAE17AX_InitEth(&ETHParameters);

TECRData ECRData;
TPOSData POSData;
int TransactionResult;
strcpy(ECRData.Amount, “00000001”);
strcpy(ECRData.PaymentType, “0”);
strcpy(ECRData.ECRId, “12345678”);
strcpy(ECRData.TerminalId, “87654321”);
TransactionResult = IAE17AX_Payment(&ECRData, &POSData);

ECRData e POSData sono puntatori alle strutture

------------------------------------------
STRUCT TETHParameters
MEMBER IPAddress As STRING LEN 16
MEMBER Port As _INT
ENDSTRUCT
ETHParameters:=ThisStruct(TETHParameters)
ECRData:=ThisStruct(TECRData)
POSData:=ThisStruct(TPOSData)
ETHParameters:IPAddress:="192.168.1.2"
ETHParameters:Port:=1234
IAE17AX_InitEth(@ETHParameters)

STRUCT TECRData
MEMBER Amount As STRING LEN 8+1
MEMBER ECRId As STRING LEN 8+1
MEMBER PaymentType As STRING LEN 1+1
MEMBER TerminalId As STRING LEN 8+1
ENDSTRUCT
STRUCT TPOSData
MEMBER TerminalId As STRING LEN 8+1
MEMBER AcquirerId As STRING LEN 11+1
MEMBER TransactionType As STRING LEN 3+1
MEMBER TransactionResult As STRING LEN 2+1
ENDSTRUCT
ECRData:Amount:="00000001"+chr(0)
ECRData:PaymentType:="0"+chr(0)
ECRData:ECRId:="12345678"+chr(0)
ECRData:TerminalId:="87654321"+chr(0)
TransactionR:=IAE17AX_Payment(@ECRData,@POSData)

DLL32 FUNCTION IAE17AX_InitEth(@ETHParameters AS PTR) AS VOID PASCAL LIB "IAE17.DLL"
DLL32 FUNCTION IAE17AX_Payment(@ECRData AS PTR, @POSData AS PTR) AS _INT PASCAL LIB "IAE17.DLL"
a.tixi@htech.it
 
Posts: 20
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Postby Enrico Maria Giordano » Tue Mar 21, 2017 6:00 pm

Invece di usare AS PTR prova ad usare una LPSTR e assegnala poi alla proprietà cBuffer della struct.

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

Re: Collegare una DLL con C Struttura

Postby a.tixi@htech.it » Wed Mar 22, 2017 1:32 pm

Ho provato ad usare cBuffer ... ma ancora niente. Potrebbero essere i tipi di dati in TETHParameters ? Ho usato la funzione StrPtr() per passare il puntatore alla struttura:

STRUCT TETHParameters
MEMBER IPAddress As STRING LEN 16
MEMBER Port As STRING LEN 6
ENDSTRUCT
ETHParameters:=ThisStruct(TETHParameters)
ECRData:=ThisStruct(TECRData)
POSData:=ThisStruct(TPOSData)
ETHParameters:IPAddress:="192.168.1.2"
ETHParameters:Port:=1234
ETHBuffer:=ETHParameters:cBuffer
IAE17AX_InitEth(@ETHBuffer)

STRUCT TECRData
MEMBER Amount As STRING LEN 8+1
MEMBER ECRId As STRING LEN 8+1
MEMBER PaymentType As STRING LEN 1+1
MEMBER TerminalId As STRING LEN 8+1
ENDSTRUCT
STRUCT TPOSData
MEMBER TerminalId As STRING LEN 8+1
MEMBER AcquirerId As STRING LEN 11+1
MEMBER TransactionType As STRING LEN 3+1
MEMBER TransactionResult As STRING LEN 2+1
ENDSTRUCT
ECRData:Amount:="00000001"+chr(0)
ECRData:PaymentType:="0"+chr(0)
ECRData:ECRId:="12345678"+chr(0)
ECRData:TerminalId:="87654321"+chr(0)
ECRBuffer:=StrPtr(ECRData:cBuffer)
POSBuffer:=StrPtr(POSData:cBuffer)
TransactionR:=IAE17AX_Payment(@ECRBuffer,@POSBuffer)

DLL32 FUNCTION IAE17AX_InitEth(@ETHBuffer AS LPSTR) AS VOID PASCAL LIB "IAE17.DLL"
DLL32 FUNCTION IAE17AX_Payment(@ECRBuffer AS PTR, @POSBuffer AS PTR) AS _INT PASCAL LIB "IAE17.DLL"
a.tixi@htech.it
 
Posts: 20
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Postby Enrico Maria Giordano » Wed Mar 22, 2017 1:55 pm

Non devi usare puntatori ma solo stringhe, altrimenti non credo ti funzionerà mai. Le stringhe poi devi prepararle (se sono in input) o interpretarle (se sono in output) secondo il tracciato desiderato. Non so se mi sono spiegato bene.

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

Re: Collegare una DLL con C Struttura

Postby a.tixi@htech.it » Wed Mar 22, 2017 3:18 pm

Dov'è che sbaglio ?

STRUCT TETHParameters
MEMBER IPAddress As STRING LEN 16
MEMBER Port As STRING LEN 6 // STRING ?? _INT ??
ENDSTRUCT
ETHParameters:=ThisStruct(TETHParameters)
ECRData :=ThisStruct(TECRData)
POSData :=ThisStruct(TPOSData)
ETHParameters:IPAddress:="192.168.1.2"
ETHParameters:Port :=4151
ETHBuffer :=ETHParameters:cBuffer // Stringa in Input
IAE17AX_InitEth(@ETHBuffer)

ECRData:Amount:="00000001"+chr(0)
ECRData:PaymentType:="0"+chr(0)
ECRData:ECRId :="12345678"+chr(0)
ECRData:TerminalId :="87654321"+chr(0)
ECRBuffer :=ECRData:cBuffer // Stringa in Input
POSBuffer :=POSData:cBuffer // Stringa in Output
TransactionR:=IAE17AX_Payment(@ECRBuffer,@POSBuffer)
DLL32 FUNCTION IAE17AX_InitEth(ETHBuffer AS LPSTR) AS VOID PASCAL LIB "IAE17.DLL"
DLL32 FUNCTION IAE17AX_Payment(@ECRBuffer AS LPSTR, @POSBuffer AS LPSTR) AS _INT PASCAL LIB "IAE17.DLL"
a.tixi@htech.it
 
Posts: 20
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Postby Enrico Maria Giordano » Wed Mar 22, 2017 3:24 pm

Ti consiglio di fare direttamente un wrapper in C, è più semplice.

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

Re: Collegare una DLL con C Struttura (RISOLTO !!!)

Postby a.tixi@htech.it » Wed May 24, 2017 4:34 pm

Ho risolto con wrapper in C, ma c'era anche una inesatezza nel .h del produttore !!!
typedef struct
{
char IPAddress[16]; //xxx.xxx.xxx.xxx
char[5] Port; // invece di int Port;
} TETHParameters;

Grazie per il suggerimento
a.tixi@htech.it
 
Posts: 20
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Postby a.tixi@htech.it » Wed May 24, 2017 4:38 pm

--- volevo scrivere char Port[5]
a.tixi@htech.it
 
Posts: 20
Joined: Thu May 14, 2009 7:45 am


Return to All products support

Who is online

Users browsing this forum: No registered users and 5 guests