Click to See Complete Forum and Search --> : Can an int to a pointer


Joshua
02-12-2001, 11:32 PM
in C++ you can do this:

int x = obj.GetAddressOfSomeObject(); // returns int
SomeObject* pSomeObject = (SomeObject*)x;

Let's say that SomeObject is a legacy COM object. So I create a stub using
TLBImp.exe, which will allow me to use the Objects from a managed enviroment.


My problem is that I needed to call the same GetAddressOfSomeObject(), the
address it will return points to an object that was not created on the managed
heap. so I cant do this in C#:

SomeObject someObject = obj.GetAddressOfSomeObject();

Can someone help me? do I need to use MC++ for this? or can use unsafe code?

Thanks.

Jeff Peil
02-13-2001, 04:00 AM
"Joshua" <chaimnus@hotmail.com> wrote in message
news:3a88b8e4$1@news.devx.com...
>
> Can someone help me? do I need to use MC++ for this? or can use unsafe
code?
>

You can do this in a C# function even without marking it as unsafe, but you
need to use the System.Runtime.InteropServices.GetObjectForIUknown() method
to get a managed wrapper for the COM object.