ProtocolPirate
Programmer
I would like to create a base class which can generically handle marshaling different table structures to unmanaged Brieve calls. I'm trying to avoid repeating the whole implementation for each different table structure. So I need to be able to do things like:
'Initialize the marshaling
m_dataLength = Marshal.SizeOf(myStruct)
m_ptr = Marshal.AllocCoTaskMem(m_dataLength)
Marshal.StructureToPtr(myStruct, m_ptr, True)
and
'Return a structure from unmanaged memory to managed memory
Native.BtrCall(Operation.GetFirst, m_posblk, m_ptr, m_dataLength, ...)
myStruct = Marshal.PtrToStructure(m_ptr, GetType(myStruct)) ' return this to the derived class
Where myStruct could be a number of different types of table structures. (And m_ptr is an IntPtr). I need to be able get these different structures passed to the marshaling functions in a generic way, such as with the type Object. On the call to Marshal.PtrToStructure(m_ptr, GetType(myStruct)) I can assign the return value to an Object and it works great, but when I pass a table structure in to the top three lines as an Object parameter the program quickly hangs after just a few calls to the unmanaged code.
Is there a way to do this so that I can get reusable code?