Skip to main content
gamedev.net
🔒 Locked

Using native types in a managed program

Started by axv4745 May 31, 2006 at 10:56 AM 1 replies 500+ views
Original Post
axv4745
axv4745
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 #include #include #using 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,
RDragon1
RDragon1
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.
axv4745
axv4745
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,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.