我必須在VB.net中創建一個結構類型的數組。但在編組此錯誤時出現錯誤。我必須將這個結構類型的數組傳遞給Dll函數。VB.net編組錯誤
代碼: 結構聲明:
Dim stpDx(2) As dx_entry
stpDx(1).dx = "5939" & Space(6)
stpDx(1).type = "BK" & Space(1)
stpDx(1).narray = Space(1)
stpDx(1).ctier = Space(1)
stpDx(1).poa = "Y"
stpDx(1).poa_rsvd = Space(1)
stpDx(1).filler = Space(81)
stpDx(2).dx = "1231" & Space(6)
stpDx(2).type = "BF" & Space(1)
stpDx(2).narray = Space(1)
stpDx(2).ctier = Space(1)
stpDx(2).poa = "Y"
stpDx(2).poa_rsvd = Space(1)
stpDx(2).filler = Space(81)
Dim pDxBuf As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(stpDx))
Marshal.StructureToPtr(stpDx, pDxBuf, False)
ezg_Block.pDx = pDxBuf
我收到以下錯誤:
An unhandled exception of type 'System.ArgumentException' occurred in Audit_Demo_2307.exe
其他信息:鍵入dx_entry [
initiallization和編組的<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure dx_entry
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=10)> _
Public dx As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=3)> _
Public type As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
Public narray As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
Public ctier As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
Public poa As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> _
Public poa_rsvd As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=81)> _
Public filler As String
End Structure
代碼]不能作爲非託管結構進行編組;無法計算出有意義的大小或偏移量。
非常感謝弗雷德裏克, 請讓我知道,如果我有該DLL後中檢索數據函數調用,我該如何去做這件事。 實際上在這個結構中有一些值會在函數調用後得到提升。 – Yogi 2009-07-23 15:10:11