Structure Array Pointers

EJ Hunt

New member
Joined
Apr 12, 2006
Messages
1
Programming Experience
5-10
I have a problem that I can not figure out. I am trying to pass an array of a structure to a C++ DLL..

TFXLibPtrTest2(PGNDesc *pDesc, INT32 i32Index);


I have used the following code to declare the function.

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure PGNDesc
Public i32PGN As Int32
Public u8GrpFunction As Short
Public i8GrpFunctionFieldNo As Short
Public i8InstanceFieldNo As Short
Public u8Priority As UShort
Public bDestGlobal As UShort
Public eProtocol As Integer
Public u8FieldCnt As UShort
Public pFieldList As IntPtr
Public i16DataByteCount As Int16
Public pPropQualifier As IntPtr
Public pMaskValue As IntPtr
End Structure


Public Class PGNComm
Public Declare Auto Function TFXLibPtrTest2 Lib "TFXCAN.dll" Alias "TFXLibPtrTest2" (ByRef PGNArray As PGNDesc, ByVal lIndex As Integer) As Integer
End Class


Here is the code to call the function:

Public Shared Sub Main()
Dim X As Integer = 10
Dim I As Integer, lResult As Integer
Dim oPGNDesc(3) As PGNDesc
For I = 0 To 2
oPGNDesc(I) = New PGNDesc
Next

For I = 0 To 2
With oPGNDesc(I)
.i32PGN = 100
.u8GrpFunction = 101
.i8GrpFunctionFieldNo = 102
.i8InstanceFieldNo = 103
.u8Priority = 104
.bDestGlobal = 105
.eProtocol = 106
.u8FieldCnt = 107
.pFieldList = VarPtr(X)
.i16DataByteCount = 109
.pPropQualifier = VarPtr(X)
.pMaskValue = VarPtr(X)
End With

Next


lResult = Teleflex.TFXLibPtrTest2(oPGNDesc, 0)

This obviously does not work. Any help you can give me would greatly be appreciated.
 
Back
Top