According to
this thread on the MSDN forums[
^], you need to change the parameter to be an
IntPtr
, allocate the memory to store the structure, and then use
PtrToStructure
to read the data into your structure.
<DllImport("ConvertRaw.dll", CallingConvention:=CallingConvention.Cdecl)>
Public Function OpenRawFile(<MarshalAs(UnmanagedType.LPStr)> x As String, ByVal CurrentStamp As IntPtr) As Integer
End Function
...
Dim result As Integer
Dim stamp1 As RawDataHeader
Dim sizeOfHeader As Integer = Marshal.SizeOf(GetType(RawDataHeader))
Dim pHeader As IntPtr = Marshal.AllocCoTaskMem(sizeOfHeader)
Try
result = OpenRawFile("C:\Raw_Data\H12091.raw", pHeader)
stamp1 = DirectCast(Marshal.PtrToStructure(pHeader, GetType(RawDataHeader)), RawDataHeader)
Finally
Marshal.FreeCoTaskMem(pHeader)
End Try
NB: This will involve copying the data returned from the C++ method, so the performance might not be great.