R
Robin Tucker
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL)
into a byte array. I know the size of the array required and I've got a
pointer to the blob, but I can't see how to copy the memory across.
Using Marshal.PtrStructure doesn't work - it says my byte() array is not
blittable! (byte is a blittable type however). Cannot use Marshal.Copy,
because that works the other way around (for mashalling to COM, not from
it).
Any ideas?
Dim theLocked As IntPtr
Try
' Find out how big the HGLOBAL allocation returned is
Dim theAudioSize As Integer = GlobalSize(hAudio)
' an array to store the WAV
Dim theSound As System.Byte()
' Resize the array
ReDim theSound(theAudioSize)
' Now, lock its buffer so we can load it in to our variable.
theLocked = GlobalLock(hAudio)
' Marshal "theLocked" into the array
??????????????????????
Catch Ex As Exception
' Whoops
Finally
Marshal.FreeHGlobal(theLocked)
End Try
into a byte array. I know the size of the array required and I've got a
pointer to the blob, but I can't see how to copy the memory across.
Using Marshal.PtrStructure doesn't work - it says my byte() array is not
blittable! (byte is a blittable type however). Cannot use Marshal.Copy,
because that works the other way around (for mashalling to COM, not from
it).
Any ideas?
Dim theLocked As IntPtr
Try
' Find out how big the HGLOBAL allocation returned is
Dim theAudioSize As Integer = GlobalSize(hAudio)
' an array to store the WAV
Dim theSound As System.Byte()
' Resize the array
ReDim theSound(theAudioSize)
' Now, lock its buffer so we can load it in to our variable.
theLocked = GlobalLock(hAudio)
' Marshal "theLocked" into the array
??????????????????????
Catch Ex As Exception
' Whoops
Finally
Marshal.FreeHGlobal(theLocked)
End Try