Reputation: 1443
I want to print the memory address of my .NET compiled object imported with DLL. The code for pinned object are (googling):
' dim managed variable
Dim primitiveObject As String="HELLO WORLD"
' pin variable and create
' GC handle instance
Dim gh As GCHandle = GCHandle.Alloc(primitiveObject , GCHandleType.Pinned)
' get address of variable
Dim AddrOfMyString As IntPtr = gh.AddrOfPinnedObject()
Console.WriteLine(AddrOfMyString.ToString())
' free the handle and unpin variable
gh.Free()
This code works perfectly, but my .NET Compiled object is not primitive type.
Dim myComObject as New MyDLL.MyNETObject
How to print myComObject memory address? Thanks in advance...
Upvotes: 1
Views: 275
Reputation: 942297
A core feature of COM is that the implementation of a COM interface is completely invisible. Only the interface pointers have a meaning, starting with IUnknown*. You can technically see the method pointers from the interface pointer, but they may well be pointing to a proxy of the interface, code that talks to another machine half-way around the world.
Marshal.GetObjectForIUnknown() may look attractive, but that represents the Runtime Callable Wrapper instance, not the actual COM object.
You should thus never try to obtain such a "memory address", it has no meaning. And for that matter, as meaningless as the address of a managed object that isn't pinned anymore.
Upvotes: 2