I have a IntPtr that points to a byte array in unmanaged memory.
How can i copy this to a managed byte array or structure?
Printable View
I have a IntPtr that points to a byte array in unmanaged memory.
How can i copy this to a managed byte array or structure?
you probably need to look up Marshal attributes . PtrToStructure is what you're looking for *maybe* .
ok, heres the structure
VB Code:
<StructLayout(LayoutKind.Sequential)> _ Public Structure TOC <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _ Dim TOC_LEN() As Byte Dim FirstTrack As Byte Dim LastTrack As Byte <MarshalAs(UnmanagedType.ByValArray, SizeConst:=800)> _ Dim TrackInfo() As Byte End Structure
VB Code:
'Heres where the buffer is allocated Dim xTOC as new TOC Dim memptr As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(xToc)) Marshal.StructureToPtr(xToc, memptr, False) 'This is now passed to a api call to be filled
VB Code:
'Heres where i try to read the data the was put intot the structure by the api call Dim Data As TOC = CType(Marshal.PtrToStructure(psrb.SRB_BufPointer, GetType(TOC)), TOC) 'none of the values in data are set???