Calling DLL's from Delphi
Help !!
I trie to call a function from a DLL called scom32. The DLL is written
in MSVC++ 4.00
and i only have the headerfile. I have converted the headerfile to
delphi and try to call
the funtion. But something goes wrong with i think passing the function
arguments. When
the function i call only has one argument then the call works, but when
i have two or more
arguments the call actualy changes arguments wich normally would't
change.
Here is what i did:
-------------- C-header:
typedef struct tagPCDCONN
{
int Port;
int Protocol;
int Baud;
BYTE Sbusmode;
BOOL bEPROM;
BYTE TxMsg[270];
typedef PCDCONN FAR *LPCONN;
int WINAPI PcdComOpen(LPCONN);
int WINAPI PcdRdVersion(LPCONN,LPSTR);
-------------- This is my DELPHI equivalent:
type
PCDCONN = Record
Port :Integer;
Protocol:Integer;
Baud :Integer;
Sbusmode:Byte;
bEPROM :Longbool;
TxMsg :Array[0..269] of Byte;
end;
var
LPCONN : ^PCDCONN;
Version: Array [0..127] of AnsiChar;
Status : Integer;
function PcdComOpen(LPCONNEC:PCDCONN):Integer;
far; pascal; external 'SCOM32';
function PcdRdVersion(LPCONNEC:PCDCONN;Version:PChar):Integer;
far; pascal; external 'SCOM32';
-------------- And so i call the functions --------
begin
getmem(LPCONN,SizeOf(PCDCONN);
PCDCONN^.Port:=0;
etc.etc.
status:=PcdComOpen(PCDCONN^); {1}
status:=PcdRdVersion(PCDCONN^,Version); {2}
freemem(LPCONN,SizeOf(PCDCONN);
end;
When i check what is returned in the status then i can only say it works
correct (in statement
{1} as well in {2}). But in statement {2} the result in 'version' is
wrong and
'PCDCONN' value's are destroyed. Only the first two fields are not
correct anymore,
so i suspect it has something to do with memory allocation or with
passing the
function arguments. I have searched for two days but can't seem to find
out what the problem
is.
Is there anyone who can help me !!!
Kind Regards,
Rene Reuscher, ANTONIUS Vessel heads