Calling Managed C++ Wrapper From C+ (Almost got it.) 
Author Message
 Calling Managed C++ Wrapper From C+ (Almost got it.)

Got it!  I found another post with a similar problem.

I just had to add a empty declaration of the dxWorld struct to one of my
header files

struct dxWorld{};

I guess that forced the compiler export the dxWorld definition or
something...  My c++ lingo is a bit lacking!


Quote:
> I need some help wrapping some old C code with managed C++ for use in C#.
> I have a lib file called ode.lib and a set of header files that came with
> it.
> I started a new Managed C++ app and set properties to include the
directory
> with the header files. I also added the line:
> #pragma comment(lib,"ode.lib") to my Stdafx.h header. All this seems to be
> fine as it all compiles cleanly.
> I made a new .h and .cpp file for my wrapper code.  Here is my code:

> .h file
> -----------------------------------
> #pragma once
> namespace ODEManaged
> {
>    __gc public class World
>      {
>      public:
>          World(void);
>          ~World(void);
>      private:
>          dWorldID *_id;
>  };
> }

> .cpp file
> -------------------------------------
> #include "StdAfx.h"
> #include <ode/ode.h>
> #include "world.h"
> #using <mscorlib.dll>

> namespace ODEManaged
> {
>    World::World(void)
>    {
>       *_id = dWorldCreate();
>    }

>    World::~World(void)
>    {
>    }
> }

> This all still compiles fine, but when I try call it from a C# test app
with
> the following code:

> ODEManaged.World w = new ODEManaged.World();

> I get the following error in my c# application when it trys to new up the
> World object.

> "An unhandled exception of type 'System.TypeLoadException' occurred in
> ODEManagedTester.exe
> Additional information: Could not load type dxWorld from assembly
> ODEManaged, Version=1.0.950.34701, Culture=neutral, PublicKeyToken=null."

> dWorldID is a struct or something of type dxWorld down in the C code I
> believe. Here a code snippet from one of the header files that came with
the
> ode.lib.

> struct dxWorld; /* dynamics world */typedef struct dxWorld *dWorldID;

> I feel i'm missing something. Is there another way I should be doing this?
> Any hints or help is appreciated.

> -jeff



Wed, 26 Jan 2005 23:36:03 GMT  
 Calling Managed C++ Wrapper From C+ (Almost got it.)
We are looking to see whether the compiler and linker can do this
automatically for a future release. We all agree it isn't very intuitive.

Ronald Laeremans
Visual C++ compiler and libraries team


Quote:
> Got it!  I found another post with a similar problem.

> I just had to add a empty declaration of the dxWorld struct to one of my
> header files

> struct dxWorld{};

> I guess that forced the compiler export the dxWorld definition or
> something...  My c++ lingo is a bit lacking!



> > I need some help wrapping some old C code with managed C++ for use in
C#.
> > I have a lib file called ode.lib and a set of header files that came
with
> > it.
> > I started a new Managed C++ app and set properties to include the
> directory
> > with the header files. I also added the line:
> > #pragma comment(lib,"ode.lib") to my Stdafx.h header. All this seems to
be
> > fine as it all compiles cleanly.
> > I made a new .h and .cpp file for my wrapper code.  Here is my code:

> > .h file
> > -----------------------------------
> > #pragma once
> > namespace ODEManaged
> > {
> >    __gc public class World
> >      {
> >      public:
> >          World(void);
> >          ~World(void);
> >      private:
> >          dWorldID *_id;
> >  };
> > }

> > .cpp file
> > -------------------------------------
> > #include "StdAfx.h"
> > #include <ode/ode.h>
> > #include "world.h"
> > #using <mscorlib.dll>

> > namespace ODEManaged
> > {
> >    World::World(void)
> >    {
> >       *_id = dWorldCreate();
> >    }

> >    World::~World(void)
> >    {
> >    }
> > }

> > This all still compiles fine, but when I try call it from a C# test app
> with
> > the following code:

> > ODEManaged.World w = new ODEManaged.World();

> > I get the following error in my c# application when it trys to new up
the
> > World object.

> > "An unhandled exception of type 'System.TypeLoadException' occurred in
> > ODEManagedTester.exe
> > Additional information: Could not load type dxWorld from assembly
> > ODEManaged, Version=1.0.950.34701, Culture=neutral,

PublicKeyToken=null."

- Show quoted text -

Quote:

> > dWorldID is a struct or something of type dxWorld down in the C code I
> > believe. Here a code snippet from one of the header files that came with
> the
> > ode.lib.

> > struct dxWorld; /* dynamics world */typedef struct dxWorld *dWorldID;

> > I feel i'm missing something. Is there another way I should be doing
this?
> > Any hints or help is appreciated.

> > -jeff



Thu, 27 Jan 2005 01:13:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

2. Managed C++ wrappers for unmanaged C++ classes

3. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

4. Newbie: separate big .cs file into small .cs files

5. Interface of Managed C++ wrappers

6. Referencing data from unmanaged code to managed code in C++ Wrapper class

7. Managed C++ Wrapper

8. Managed C++ "wrapper classes" deployment problem

9. Managed C++ Wrapper for DLL

10. Tutorial wanted for using a managed C++ class wrapper

11. Creating a managed C++ class wrapper

12. Extended MAPI in c++ managed code wrapper

 

 
Powered by phpBB® Forum Software