Collegare una DLL con C Struttura

Moderator: Enrico Maria Giordano

Post Reply
a.tixi@htech.it
Posts: 18
Joined: Thu May 14, 2009 7:45 am

Collegare una DLL con C Struttura

Post by a.tixi@htech.it »

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"
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Collegare una DLL con C Struttura

Post by Enrico Maria Giordano »

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

EMG
a.tixi@htech.it
Posts: 18
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Post by a.tixi@htech.it »

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"
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Collegare una DLL con C Struttura

Post by Enrico Maria Giordano »

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
a.tixi@htech.it
Posts: 18
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Post by a.tixi@htech.it »

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: 18
Joined: Thu May 14, 2009 7:45 am

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

Post by a.tixi@htech.it »

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: 18
Joined: Thu May 14, 2009 7:45 am

Re: Collegare una DLL con C Struttura

Post by a.tixi@htech.it »

--- volevo scrivere char Port[5]
Post Reply