我尝试将这些VB6类型转换为VB.NET世界。将VB6类型转换为VB.NET数组结构
Type TRACK_DATA
Dim reserved As Byte
Dim Control As Byte
Dim Tracknumber As Byte
Dim reserved1 As Byte
Dim address As Long
End Type
Type CDTOC
Dim Length As Long
Dim FirstTrack As Byte
Dim LastTrack As Byte
Dim Tracks(100) As TRACK_DATA
End Type
当前的尝试悲惨的失败了
<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size:=8)>
Structure TRACK_DATA
Public reserved As Byte
Public Control As Byte
Public Tracknumber As Byte
Public reserved1 As Byte
Public address As UInteger
End Structure
<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size:=806)>
Structure CDROM_TOC '4 + 1 + 1 + 800 = 806
Public Length As UInteger
Public FirstTrack As Byte
Public LastTrack As Byte
Public Tracks() As TRACK_DATA
End Structure
...
Dim MyCD As CDTOC
ReDim MyCD.Tracks(100)
任何提示如何做到这一点?
它传递参数,并让他们回到外部DLL,所以我用编组站但Marshal.SizeOf(MyCD)
返回错误值(12)如果我不使用互操作规模,并韦尔普,与StructureToPtr所有attemps结束错误。下面
的代码,如果任何使用的理解:
Toc_len = Marshal.SizeOf(MyCD)
Dim Toc_ptr As IntPtr = Marshal.AllocHGlobal(CInt(Toc_len))
'open the drive
...
'access to the TOC
DeviceIoControl(hFile, IOCTL_CDROM_READ_TOC, IntPtr.Zero, 0, Toc_ptr, Toc_len, BytesRead, IntPtr.Zero)
'copy back the datas from unmanaged memory
'fails here !
MyCD = Marshal.PtrToStructure(Toc_ptr, CDTOC.GetType())
对于记录,VB6的'Long'通常映射到'Integer',而不是'UInteger'(除非DLL需要UInts,就是这样)。 –