For Programmers: Free Programming Magazines  


Home > Archive > Clarion > December 2006 > Delphi Conversion Accessing a DLL using CLARION









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Delphi Conversion Accessing a DLL using CLARION
Michael

2006-12-11, 6:57 pm

Hi all,
Help !! Help !!!

I am trying to use a 3rd party DLL, the 3rd party has provided sample
code for Delphi V7.

In Delphi the following is defined.

type
PstPollRecord=^TstPollRecord;
TstPollRecord=record
iClassCode:Integer; //Class Code
iIllegalCode:Integer; //Illegal Code
cDateTime:array[0..19] of Char; //Date Time
cCard:array[0..19] of Char; //Card Number
cDeviceID:array[0..9] of Char; //Device ID

end;

//Send Polling To HTA
function
htaPolling(hComm:THandle;iNodeID,iPrevRe
cord:Integer;stPollList:PstPollRecord;va
r
iRecord:Integer;iCardType:Integer;iTimeO
ut:DWORD):Integer;stdcall;external
'HTA8.dll';

Clarion Equivalent:my strut is declared as:
! in Global Data Defention

PstPollRecord GROUP,PRE()
TstPollRecord GROUP,TYPE,PRE(),DIM(60)
iClassCode SHORT
iIllegalCode SHORT
cDateTime CSTRING(20)
cCard CSTRING(20)
cDeviceID CSTRING(10)
END
END

In Clarion I prototyped my function as:

htaPolling (UNSIGNED hComm, SHORT iNodeID, SHORT giPrevRecord,
*PstPollRecord stPollList, *SHORT iRecord, SHORT iCardType, USHORT
iTimeOut), SHORT,PASCAL,RAW

The problem I cant received data in proper way, the solution I think in
data structure, any help Please!....

Thanks !
Michael




In Delphi the Code as following:

(***************************************
****************************************

Function: TfrmHTADemo.btnhtaPollingClick
Description: NONE
Input: Sender: TObject
Output: NONE
Others: NO
****************************************
***************************************)

procedure TfrmHTADemo.btnhtaPollingClick(Sender: TObject);
var
iRecord,i:Integer;
cBuf:array[0..1024] of Char;
stPollList:PstPollRecord;
begin
pnlCommand.Enabled:= False;
btnhtaPolling.Enabled:= False;
try
stPollList:= @cBuf[0];
for i:= 0 to chklstPolling.Items.Count-1 do
begin
if chklstPolling.Checked[i] then
begin
//must to polling data
FillChar(cBuf,SizeOf(cBuf),0);
iResult:=
htaPolling(hComm,i+1,giPrevRecord[i],stP
ollList,iRecord,Integer(chkCompress.Checked),iTimeOut-2000);
if iResult=htaSuccess then
begin
giPrevRecord[i]:= iRecord;
//'htaPolling OK. ID:'+inttostr(i+1)+' Reutrn:'+
ShowInfo(
' Class
Code:'+inttohex(stPollList.iClassCode,4)+
'
DateTime:'+strpas(stPollList.cDateTime)+
' Card Number:'+strpas(stPollList.cCard)+
' Device
ID:'+strpas(stPollList.cDeviceID)+
' Legal
Code:'+inttohex(stPollList.iIllegalCode,4)
);
Application.ProcessMessages;
end
else
begin
//Maybe No Data.
//must Continue Next Device
//so Cann't Exit and show any Error msg.

//ShowInfo('htaPolling Failed, ID:'+inttostr(i+1)+'
Msg:'+GetErrorDes(iResult));
//Exit;
end;
end;
end;
finally
pnlCommand.Enabled:= True;
btnhtaPolling.Enabled:= True;
end;
end;

procedure TfrmHTADemo.FormCreate(Sender: TObject);
begin
FillChar(giPrevRecord,sizeof(giPrevRecor
d),0);
end;

procedure TfrmHTADemo.pnlNormalCmdClick(Sender: TObject);
begin
//
end;

clackmannan

2006-12-11, 6:57 pm


Michael wrote:
>
> type
> PstPollRecord=^TstPollRecord;
> TstPollRecord=record
> iClassCode:Integer; //Class Code
> iIllegalCode:Integer; //Illegal Code
> cDateTime:array[0..19] of Char; //Date Time
> cCard:array[0..19] of Char; //Card Number
> cDeviceID:array[0..9] of Char; //Device ID
>
> end;
>


Try this. The most obvious thing wrong with your previous definition
was the "DIM(60)", unless there's something else you're not telling us
:)

TstPollRecord Group,Type
iClassCode Short
iIllegalCode Short
cDateTime CString(20)
cCard CString(20)
cDeviceID CString(10)
End ! Group

In Delphi PstPollRecord is declared as "^TstPollRecord" which almost
certainly means "Pointer to TstPollRecord"

You get the same thing in Clarion by doing

mygroup like(TstPollRecord)
mypointer ulong
code
mypointer = address(mygroup)

Your prototype may or not be correct, I don't know enough about Dephi
types to know what their CW equivalent is.

If your vendor gave you C versions of the structure & procedure
definitions then it's normally easier to convert from them, as there's
more resources available to help you.

HTH,
Paul

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com