EDN Admin
Well-known member
<P>Mathew Gertz pointed me in the right direction I believe in an earlier post.
My P/Invoke is returning valid values for name below at field offset 0 and other values as I can see in QuickWatch.
StructA below is passed and returned from the unmanaged C++ dll with valid values.
An error is thrown however;
System.ExecutionEngineException was unhandled
Message="Exception of type System.ExecutionEngineException was thrown."
I would like to try Mathews idea of using <STRONG>LayoutKind.Explicit</STRONG> rather than LayoutKind.Sequential which I am currently using.
<STRONG>If I had <FieldOffset(0)> for the first member of StructA, can anyone help me with how the rest would look?
I would say Offsets would increase by
1. 4 after each Integer
2. 8 after each double</STRONG></P>
<P><STRONG>But how much offset do I allocate for
1. the VBFixedString(128) datatype
2. StructB
3. StructC</STRONG></P>
<P><STRONG>Do StructB and StructC require the same attributes applied to them as well ("<StructLayout(Layout.......) ?
</STRONG>Thank you kindly for any help on this interesting challenge
interesting that vb6 handled this translation but I am having to work at it to get it to work for .NET</P>
<P>-Greg</P>
<P>
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Public Structure <STRONG>StructA</STRONG>
<<STRONG>VBFixedString(128), </STRONG>System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=128)> Public <STRONG>name</STRONG>() As Char
Dim var2 As Integer
Dim var3 As Integer
Dim var4() As Double
Dim var5 As Double
Dim var6() As Double
Dim var7 As Double
Dim var8 As Double
Dim var9 As Integer
Dim var10 As Integer
Dim var11() As <STRONG>StructB</STRONG>
Dim var12 As <STRONG>StructC</STRONG>
Public Sub Initialize()
ReDim var4(2)
ReDim var6(2)
ReDim var11 (19)
var12.Initialize()
End Sub
End Structure</P>
<P>where</P>
<P>Public Structure <STRONG>StructB </STRONG>
Dim ivar1 As Integer
Dim ivar2 As Integer
Dim var3 As Double
Dim var4() As Double
Public Sub Initialize()
ReDim var4(2)
End Sub
End Structure</P>
<P>and </P>
<P>Public Structure <STRONG>StructC</STRONG>
Dim SegmentType As SEGMENTTYPE enumerated value
Dim var2 As Integer
Dim var3() As Double
Dim var4(,) As Double
Dim var5(,) As Double
Dim var6(,) As Double
Public Sub Initialize()
ReDim var3(2)
ReDim var4(2, 2)
ReDim var5(1, 5)
ReDim var6(1, 5)
End Sub
End Structure</P>
<P> </P>
<P>int EXPORTED GetStructStuff(long Index, sStructA* pStructA) C++ function being called</P>
<P> </P>
View the full article
My P/Invoke is returning valid values for name below at field offset 0 and other values as I can see in QuickWatch.
StructA below is passed and returned from the unmanaged C++ dll with valid values.
An error is thrown however;
System.ExecutionEngineException was unhandled
Message="Exception of type System.ExecutionEngineException was thrown."
I would like to try Mathews idea of using <STRONG>LayoutKind.Explicit</STRONG> rather than LayoutKind.Sequential which I am currently using.
<STRONG>If I had <FieldOffset(0)> for the first member of StructA, can anyone help me with how the rest would look?
I would say Offsets would increase by
1. 4 after each Integer
2. 8 after each double</STRONG></P>
<P><STRONG>But how much offset do I allocate for
1. the VBFixedString(128) datatype
2. StructB
3. StructC</STRONG></P>
<P><STRONG>Do StructB and StructC require the same attributes applied to them as well ("<StructLayout(Layout.......) ?
</STRONG>Thank you kindly for any help on this interesting challenge
interesting that vb6 handled this translation but I am having to work at it to get it to work for .NET</P>
<P>-Greg</P>
<P>
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Public Structure <STRONG>StructA</STRONG>
<<STRONG>VBFixedString(128), </STRONG>System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=128)> Public <STRONG>name</STRONG>() As Char
Dim var2 As Integer
Dim var3 As Integer
Dim var4() As Double
Dim var5 As Double
Dim var6() As Double
Dim var7 As Double
Dim var8 As Double
Dim var9 As Integer
Dim var10 As Integer
Dim var11() As <STRONG>StructB</STRONG>
Dim var12 As <STRONG>StructC</STRONG>
Public Sub Initialize()
ReDim var4(2)
ReDim var6(2)
ReDim var11 (19)
var12.Initialize()
End Sub
End Structure</P>
<P>where</P>
<P>Public Structure <STRONG>StructB </STRONG>
Dim ivar1 As Integer
Dim ivar2 As Integer
Dim var3 As Double
Dim var4() As Double
Public Sub Initialize()
ReDim var4(2)
End Sub
End Structure</P>
<P>and </P>
<P>Public Structure <STRONG>StructC</STRONG>
Dim SegmentType As SEGMENTTYPE enumerated value
Dim var2 As Integer
Dim var3() As Double
Dim var4(,) As Double
Dim var5(,) As Double
Dim var6(,) As Double
Public Sub Initialize()
ReDim var3(2)
ReDim var4(2, 2)
ReDim var5(1, 5)
ReDim var6(1, 5)
End Sub
End Structure</P>
<P> </P>
<P>int EXPORTED GetStructStuff(long Index, sStructA* pStructA) C++ function being called</P>
<P> </P>
View the full article