Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi Conversion Accessing a DLL using CLARION

7 views
Skip to first unread message

Michael

unread,
Dec 8, 2006, 7:48:16 PM12/8/06
to
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,iPrevRecord:Integer;stPollList:PstPollRecord;var
iRecord:Integer;iCardType:Integer;iTimeOut: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],stPollList,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(giPrevRecord),0);
end;

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

Michael

unread,
Dec 8, 2006, 8:22:11 PM12/8/06
to

clackmannan

unread,
Dec 8, 2006, 8:39:19 PM12/8/06
to

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

Michael

unread,
Dec 9, 2006, 10:31:19 AM12/9/06
to

Thanks Paul

the 3rd party has alos provided sample code for VB6

Public Type poll
iClassCode As Integer ' //Class Code
iIllegalCode As Integer ' //Illegal Code
sDate As String
sCard As String
sDeviceID As String
' sReader As String
End Type


Declare Function htaPolling Lib "HTA8.dll" (ByVal hComm As Integer,
ByVal inodeid As Integer, ByVal iprevRecord As Integer, ByRef stRecord
As Byte, _
ByRef irecord As Integer, ByVal icardtype As
Integer, ByVal itimeout As Integer) As Integer

' htaPolling (HANDLE hComm,int iNodeID,int iPrevRecord,stPollList
*stRecord,
' int *iRecord,int
iCardType,unsigned int iTimeout);


Function polling(ByVal inodeid As Integer, ByVal icardtype As Integer)
As Boolean

Dim vPoll As Integer
Dim iRec As Integer
Dim flag As Boolean
Dim i As Integer

Dim j As Integer


Dim k As Long


Dim sEvnetCode As String
Dim IllegalCode As String
Dim sDate As String
Dim sCard As String
Dim sDeviceID As String
Dim l As String

Dim bAa() As Byte
ReDim bAa(255 * 60)
vPoll = htaPolling(rltcom, inodeid, iprevR(inodeid), bAa(0),
iRec, icardtype, 1000)

If vPoll = 0 Then
iprevR(inodeid) = iRec
Text1.Text = "polling is success!"
For i = 0 To iRec - 1
sEvnetCode = "Class Code: "
For j = 3 To 0 Step -1
sEvnetCode = sEvnetCode & Trim(Str(bAa(i * 60 +
j)))
Next j
IllegalCode = "legal Code:"
For j = 7 To 4 Step -1

IllegalCode = IllegalCode & Trim(Str(bAa(i * 60
+ j)))

Next j
sDate = "Date time: "
For j = 8 To 27
If (Asc(Chr(bAa(i * 60 + j))) > 0) Then
sDate = sDate & Chr(bAa(i * 60 + j))
End If
Next j
sCard = "Card NO: "
For j = 28 To 47
If (Asc(Chr(bAa(i * 60 + j))) > 0) Then
sCard = sCard & Chr(bAa(i * 60 + j))
End If
Next j
sDeviceID = "Device ID: "
For j = 48 To 57
If (bAa(i * 60 + j) > 0) Then
sDeviceID = sDeviceID & Chr(bAa(i * 60 + j))
End If
Next j

l = sEvnetCode & " " & sDate & " " & sCard & " " &
sDeviceID & " " & IllegalCode

List1.AddItem l
Next i
flag = True
ElseIf rltcom <> 0 Then
If vPoll = 1010 Then
Text1.Text = "The HTA" + Trim(Str(inodeid)) + " has not
data!"
flag = True
Else
Text1.Text = "Polling the HTA" + Trim(Str(inodeid)) + " is
failure!"
End If
Else
Text1.Text = "Polling the HTA" + Trim(Str(inodeid)) + " is
failure!"
flag = False
End If
polling = flag
End Function

Private Sub btnpolling_Click()
Dim vPoll As Integer
Dim flag As Boolean

Dim iRec As Integer

Dim i As Integer

Dim j As Integer

Dim icardtype As Long

Dim l As String

If Check7.Value = 1 Then
icardtype = 1
Else
icardtype = 0
End If
If Check1.Value = 1 Then
flag = polling(1, icardtype)
End If
If Check2.Value = 1 Then
flag = polling(2, icardtype)

End If
If Check3.Value = 1 Then
flag = polling(3, icardtype)

End If
If Check4.Value = 1 Then
flag = polling(4, icardtype)

End If
If Check5.Value = 1 Then
flag = polling(5, icardtype)

End If
If Check6.Value = 1 Then
flag = polling(6, icardtype)
End If

End Sub

Michael

unread,
Dec 9, 2006, 3:18:44 PM12/9/06
to
Hi all,
Help !! Help !!!

I am trying to use a 3rd party DLL, the 3rd party has provided sample

code for VB V6.


In VB the following is defined.


Dim j As Integer


Dim k As Long

+ j)))


Dim iRec As Integer


Dim i As Integer


Dim j As Integer


Dim icardtype As Long


Dim l As String


End Sub


http://groups.google.com/group/comp.lang.clarion/browse_thread/thread/16adc4fe743f2b2f?hl=en

0 new messages