PC Review


Reply
Thread Tools Rate Thread

creating an umanaged object in a managed wrapper

 
 
JRoe
Guest
Posts: n/a
 
      8th Feb 2005
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!

 
Reply With Quote
 
 
 
 
John Puopolo
Guest
Posts: n/a
 
      8th Feb 2005
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!
>



 
Reply With Quote
 
JRoe
Guest
Posts: n/a
 
      8th Feb 2005
John,
What I mean by undefined is when I look at the variables that the
constructor was supposed to instantiate in the IDE debuger they are set
to <undefined>

If the constructor was throwing an exception, wouldn't the code assert?
The managed wrapper's constructor is calling the unmanaged
constructor when I call a "new" on it:

myMapInterface = new Map_Interface;

When it returns from this new call, the values of myMapInterface are
all undefined...meaning, they are just not set.

I don't know what you mean about how is the unmanaged code loaded? The
unmanaged code is a static library (.lib) and my managed portion is a
..dll and in the .dll I have a #include to the class that I am
referencing in the .lib. I am not using PInvoke or any DLLImport
calls. Should I be? And if so, where would I need ot do this? I've
seen other examples of this at my company and they are not using
PInvoke or DLLImport calls.

Thanks,
Janine

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Managed C++...creating and hosting service object using MCPP Steven Rosenberg Microsoft Dot NET Framework 0 8th Apr 2008 07:11 PM
Filenotfoundexception occurs when creating an object from a Managed dll in a Mixed DLL ropo Microsoft Dot NET 0 20th Dec 2006 03:55 PM
Giving one managed wrapper class access to the unmanged part of another managed wrapper class mschuck Microsoft VC .NET 1 31st Aug 2006 05:27 PM
Creating a object of a wrapper dll class =?Utf-8?B?c20=?= Microsoft VB .NET 4 23rd Oct 2004 07:31 AM
Re: Trouble creating Managed Proxy for umanaged C++ in VS.Net 2003 4Space Microsoft VC .NET 0 8th Jul 2003 12:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 PM.