Jump to content
  • Advertisement
Sign in to follow this  
axv4745

Using native types in a managed program

This topic is 4431 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to write a Managed C++ class that has an unmanaged Direct3D Device as a member. Ultimately a C# class would make calls to the Managed C++ class to access the unmanaged Direct3D device to ultimately wrap it in an C# managed Direct3D Device. Unfortunately this is not working and I get the following error. error C3635: '::IDirect3DDevice9': undefined native type used in 'ManagedBridge::MDirect3D; imported native types must be defined in the importing source code Apparently I cannot write a managed C++ class that has a native Direct3D Device as a member. Here is a simple code snippet I wrote #ifndef MDIRECT3D #define MDIRECT3D #include <windows.h> #include <d3d9.h> #include <d3dx9.h> #using <mscorlib.dll> using namespace System; static LPDIRECT3DDEVICE9 deviceHandle = NULL; namespace ManagedBridge { public __gc class MDirect3D { public: inline static void SetDirect3DDevice(void * device) { deviceHandle = (LPDIRECT3DDEVICE9)device; } inline static LPDIRECT3DDEVICE9 GetDirect3DDevice() { return deviceHandle; } }; } #endif I'm simply trying to write an mc++ class that provides access to an unmanaged Direct3D device from C#. Is there another way I can do something similar to the code I wrote above? Thanks,

Share this post


Link to post
Share on other sites
Advertisement
Why not use Managed DirectX directly? I would also recommend you dump Managed C++ - it's deprecated in VS 2005 in favor of C++/CLI, which is much more natural and streamlined.

Share this post


Link to post
Share on other sites
Unfortunately we've been working on this project long before we had VS2005 and so there was no C++/CLI. I definitely agree it would be better to use C++/CLI now that we've actually made the transition to VS2005; however, we're on a tight deadline so making the transition might be costly in terms of time (this is something we'll probably be talking about soon anyway).

I actually used Managed DirectX at first; however, the application we're working with deals with objects that are in different application domains; these objects also need to use the Managed DirectX Device but apparently the Managed Device doesn't play so nicely in a multi app domain environment. I essentially ran into several runtime errors when trying to marshal the Device object accross the app domains; certain device attributes did not serialize (e.g Event Handlers) and it threw some exceptions, which leads me to believe that when Microsoft designed the Device class they didn't flag certain attributes as serializable. With the system we have currently designed using a Managed C++ class would allow me to bypass the application domain problem I am having. Assuming I could bypass the error I mentioned in the first post I will have solved my problem. Of course, if you have any other thoughts/suggestions/ideas I am all ears ;-)

Thanks,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!