.NET Marshalling

mccafferypaul

New member
Joined
Nov 23, 2006
Messages
1
Programming Experience
1-3
Hello,

I am new to these forums so forgive me if this is in the wrong place or not following the standards you would expect.

I have a problem. I need to build a complex object with linked list, retrieve the address of this object in memory, then pass it to a VB6 app using COM interop which then passes the address to another .NET assembly which takes the address and accesses the complex structure containing the linked list. (the VB6 code just passes on the IntPtr)

I am aware of the possibility of using the below code but this does not seem to work for more complex structures with non-blitable types. Is it possible?

Any help or ideas would be great. I am a bit new to this Interop stuff.
================

Dim a As AStruct
a.x = 1
a.y = 3

'Dim gh As GCHandle = GCHandle.Alloc(a, GCHandleType.Pinned)
' get address of variable
'Dim AddrOfMyString As IntPtr = gh.AddrOfPinnedObject()
'Console.WriteLine(AddrOfMyString.ToString())

Dim MyPointer As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(a))
Marshal.StructureToPtr(a, MyPointer, False)


Dim b As AStruct = CType(Marshal.PtrToStructure(MyPointer, GetType(AStruct)), AStruct)


Thanks Paul M
 
Back
Top