P
Paul Coene
The code below is snipets from my application.
I believe I have the LoadLibrary and the GetProcAddress code down pat. Several
other functions in this program get through the API, and even the ones where I
pass integers by reference work and get filled in.
My question is can I do a Structure this way? I know at least part of the
structure is working, because the DLL reacts correctly to the ProtocolID field.
My fear is that perhaps only the 1st of the (3) structures is getting through
correctly, as I pass three in a row and maybe I have some problem there? I
can't get this API call to accept 3 structures that look valid, so I fear some
corruption along the way.
Another key is the API wants a NULL pointer for the 3rd structure. You can see
below I try to do this with the nothing keyword.... Not sure about this either.
Code snips below:
Public Structure PASSTHRU_MSG
Dim ProtocolID As Integer
Dim RxStatus As Integer
Dim TxFlags As Integer
Dim Timestamp As Integer
Dim DataSize As Integer
Dim ExtraDataIndex As Integer
Dim Data() As Byte
End Structure
Private Delegate Function dPassThruStartMsgFilter(ByVal channelid As Integer, _
ByVal filtertype As Integer, _
ByRef pmaskmap As PASSTHRU_MSG, _
ByRef pPatternMsg As PASSTHRU_MSG, ByRef
pflowcontrolmsg As PASSTHRU_MSG, _ ByRef
pfilterid As Integer) As Integer
Private hPassThruStartMsgFilter As Integer
( I use LoadLibrary and GetProcAddress to get hPassThruStartMsgFilter filled
in. Left out for conciseness)
Public Function PassThruStartMsgFilter(ByVal ChannelId As Integer, _
ByVal FilterType As Integer, _
ByRef pMaskMsg As PASSTHRU_MSG, _
ByRef pPatternMask As PASSTHRU_MSG, _
ByRef pFlowControlMsg As PASSTHRU_MSG, _
ByRef pFilterId As Integer) As Integer
Dim arg() As Object
Dim ret As Integer
pFlowControlMsg.Data = Nothing
arg = New Object() {ChannelId, FilterType, pMaskMsg, pPatternMask, _
pFlowControlMsg, pFilterId}
ret = Marshal.GetDelegateForFunctionPointer(hPassThruStartMsgFilter, _
GetType(dPassThruStartMsgFilter)).DynamicInvoke(arg)
If ret = 0 Then
pFilterId = arg(5)
Form1.Status.Text += "Connection Filter(" + ChannelId.ToString _
+ ") Set" + vbNewLine
Else
Form1.Status.Text += "Connection Filter Failed: " + ret.ToString + _
vbNewLine
End If
Return ret
End Function
I believe I have the LoadLibrary and the GetProcAddress code down pat. Several
other functions in this program get through the API, and even the ones where I
pass integers by reference work and get filled in.
My question is can I do a Structure this way? I know at least part of the
structure is working, because the DLL reacts correctly to the ProtocolID field.
My fear is that perhaps only the 1st of the (3) structures is getting through
correctly, as I pass three in a row and maybe I have some problem there? I
can't get this API call to accept 3 structures that look valid, so I fear some
corruption along the way.
Another key is the API wants a NULL pointer for the 3rd structure. You can see
below I try to do this with the nothing keyword.... Not sure about this either.
Code snips below:
Public Structure PASSTHRU_MSG
Dim ProtocolID As Integer
Dim RxStatus As Integer
Dim TxFlags As Integer
Dim Timestamp As Integer
Dim DataSize As Integer
Dim ExtraDataIndex As Integer
Dim Data() As Byte
End Structure
Private Delegate Function dPassThruStartMsgFilter(ByVal channelid As Integer, _
ByVal filtertype As Integer, _
ByRef pmaskmap As PASSTHRU_MSG, _
ByRef pPatternMsg As PASSTHRU_MSG, ByRef
pflowcontrolmsg As PASSTHRU_MSG, _ ByRef
pfilterid As Integer) As Integer
Private hPassThruStartMsgFilter As Integer
( I use LoadLibrary and GetProcAddress to get hPassThruStartMsgFilter filled
in. Left out for conciseness)
Public Function PassThruStartMsgFilter(ByVal ChannelId As Integer, _
ByVal FilterType As Integer, _
ByRef pMaskMsg As PASSTHRU_MSG, _
ByRef pPatternMask As PASSTHRU_MSG, _
ByRef pFlowControlMsg As PASSTHRU_MSG, _
ByRef pFilterId As Integer) As Integer
Dim arg() As Object
Dim ret As Integer
pFlowControlMsg.Data = Nothing
arg = New Object() {ChannelId, FilterType, pMaskMsg, pPatternMask, _
pFlowControlMsg, pFilterId}
ret = Marshal.GetDelegateForFunctionPointer(hPassThruStartMsgFilter, _
GetType(dPassThruStartMsgFilter)).DynamicInvoke(arg)
If ret = 0 Then
pFilterId = arg(5)
Form1.Status.Text += "Connection Filter(" + ChannelId.ToString _
+ ") Set" + vbNewLine
Else
Form1.Status.Text += "Connection Filter Failed: " + ret.ToString + _
vbNewLine
End If
Return ret
End Function