calling a c dll functions & get reply messages from that dll
Hi all,
I have a dll that communicate with access control hardware which stores all transactions in its memory
unfortunately, all docs are in c# which I note able to manage since I know vb6 only
the main structure (Type as in vb6) has the following:
Public Structure sysReply
' Fields
<FieldOffset(0)> _
Public nsysNumber As Short
<FieldOffset(4)> _
Public nType As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=&H400), FieldOffset(8)> _
Public sBuffer As Char()
End Structur
the sbuffer array is the union of all events
what I understand that there is no union in vb6 but is UDT
so there is many UDT's thats is related to the sbuffer according to the nType in the sysReply structure
my question is how to deal with the above in vb6?
I did the following
Public type sysReply
nsysNumber As integer
nType as integer
sBuffer() As Byte
end type
public sReply as sysReply
there is other structures that is related to the nType
and use copymemory to copy the sysRply to every udt
like:
Dim bytcommstatus As sysReplyCommStatus
CopyMemory ByVal VarPtr(bytcommstatus), ByVal VarPtr(sReply), LenB(bytcommstatus)
With bytcommstatus
debug.print .status
debug.print .error_no
end with
I get get data but I face two problems
- data are not in same order as udt
- application crashes
can someone show me example?
regards
Re: calling a c dll functions & get reply messages from that dll
If the samples are in C# then VB.Net would likely be easier than VB6 for this. There is even an online converter for C# to VB.Net that works fairly well in many cases.
Re: calling a c dll functions & get reply messages from that dll
Quote:
Originally Posted by
KhaledEissa
I have a dll that communicate with access control hardware which stores all transactions in its memory
unfortunately, all docs are in c# which I note able to manage since I know vb6 only
the main structure (Type as in vb6) has the following:
Code:
Public Structure sysReply
' Fields
<FieldOffset(0)> _
Public nsysNumber As Short
<FieldOffset(4)> _
Public nType As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=&H400), FieldOffset(8)> _
Public sBuffer As Char()
End Structure
...
I did the following
Code:
Public Type sysReply
nsysNumber As integer
nType as integer
sBuffer() As Byte
end Type
Public sReply as sysReply
The above is a faulty translation from the .NET-Marshaling-Def - please correct the Struct-Def to this:
Code:
Public Type sysReply
nsysNumber As Long
nType as Long
sBuffer(0 To &H400-1) As Byte
end Type
Public sReply as sysReply
Quote:
Originally Posted by
KhaledEissa
there is other structures that is related to the nType
Then introduce alternative TypeDefs for them appropriately...
VB6 has no Union, so you have to write-up the alternatives explicitely.
Olaf
Re: calling a c dll functions & get reply messages from that dll
Thanks Schmidt for your quick answer
but can you show me example??
to make it more clear here is some of UDT's that will be related to sReply
for example when sReply comes (as stated before - I use a timer and issue a GetMessage function to the driver as following:)
Public Type sysReply
nsysNumber As Long
nType as nSReplyType
sBuffer(0 To &H400-1) As Byte
end Type
Public sReply as sysReply
Public Enum nSReplyType
sReplyIDReport = 4
sReplyACK = 1
sReplyMemRead = &H73B
sReplyTransaction = 7
sReplyCommStatus = 2
sReplyCmndStatus = 15
End Enum
Public Type sCReplyTransaction ' this if nType=7
ser_num As Integer
time As Integer
source_type As Integer
source_number As Integer
tran_type As Integer
tran_code As Integer
sys As TypeSys ' this another type
End Type
Public Type sCPReplyCommStatus this is when nType=2
status As Integer
error_code As enSCPCommErr ' this is another type
nChannelId As Integer
current_primary_comm As Integer
previous_primary_comm As Integer
current_alternate_comm As Integer
previous_alternate_comm As Integer
End Type
some declarations
Public Comm as sCPReplyCommStatus
Public Trans as sCReplyTransaction
and so many other UDT's according to nSReplyType and its nType
so what I did is:
timer code
dim sRet as integer
sRet= sGetMessage(5,sReply) ' getting buffer from the hardware
if sRet Then
'here calling function that deal with sReply according to nType
for example if nType = 7 I call a function
Public Function ProcessReply(ByVal ReplyType As Integer) As Boolean
Select Case ReplyType
Case 2
CopyMemory ByVal VarPtr(comm), ByVal VarPtr(sReply), LenB(sReply)
debpug.print comm.
Case 7
CopyMemory ByVal VarPtr(Trans), ByVal VarPtr(sReply), LenB(sReply)
Case 2
Case 2
End Select
End Function
end if
so, I'm Able to read data but it comes not in a correct sequence
any advice in my code?
regards
Re: calling a c dll functions & get reply messages from that dll
Quote:
Originally Posted by
KhaledEissa
Public Function ProcessReply(ByVal ReplyType As Integer) As Boolean
Select Case ReplyType
Case 2
CopyMemory ByVal VarPtr(comm), ByVal VarPtr(sReply), LenB(sReply)
debpug.print comm.
Case 7
CopyMemory ByVal VarPtr(Trans), ByVal VarPtr(sReply), LenB(sReply)
End Select
End Function
so, I'm Able to read data but it comes not in a correct sequence
any advice in my code?
I'd try to copy from ByVal VarPtr(sReply.sBuffer(0)) and not from ByVal VarPtr(sReply) directly.
Cannot do much more than guess from here, since I have no documentation
for your hardware - also keep in mind, that .NETs integers need to be translated
to VB6-Longs in your typedefs...
Olaf
Re: calling a c dll functions & get reply messages from that dll
thanks again indeed let me try and reply you