Hi...
When you say the object is undefined, do you mean you cannot make calls into
it (call methods on it)?
Is the unmanaged constructor possibly throwing an exception? In C++ this
will cause the new method to return an "undefined" object. In addition, how
is the unmanaged code loaded? Are you using P/Invoke with DLLImport or is
the unmanaged code in its own EXE?
John
"JRoe" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> I am beside myself with this problem.
> I need to access unmanged C++ code in a C# environment. I have created
> a managed C++ wrapper that wraps the unmanaged class.
> When I call the constructor, it is returning undefined. Here is an
> example:
>
> Unmanaged C++
>
> class Map_Interface
> {
> Map_Inteface()
> {
> ...does stuff
> }
> }
>
> Managed C++
> #using mscorlib.dll
>
> __gc class Map_Interface_Wrapper
> {
> private:
> Map_Interface __nogc *myMapInterface;
>
> public:
> Map_Interface_Wrapper()
> { myMapInterface = new Map_Interface; }
>
> };
>
>
> C# Driver
> ....
> using Map_Interface_Wrapper;
>
> Map_Interface_Wrapper aWrapper = new Map_Interface_Wrapper;
>
>
> My problem is when the C# instantiates the Map_Interface_Wrapper, the
> managed code constructor is being called and then calls the unmanaged
> C++ constructor. When I step into this I see the objects being
> initialized, but when it leaves the unmanaged constructor and returns
> to the managed wrapper, the newly created object is still undefined. I
> can see the address it is pointing to is the same as the unmanaged
> object.
> I have no idea how to fix this. I've been looking all over the
> internet to see if anyone has had this problem and can't seem to find
> it. All the documentation I've read shows to do it this way, but for
> some reason it doesn't work for me. Perhaps I have a compilier setting
> wrong in the IDE??
> I would surely appreciate help on this.
> Thanks in advance!
>
|