Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Unmanaged C++ DirectX in WinForms

Started by OrenGL Oct 1, 2004 at 5:28 AM 3 replies 4.9k views
Original Post
OrenGL
OrenGL
I know C++ but I'm new to .NET. I'm writing a game editor for an existing engine I have in C++; I'd like to use WinForms since they are much simpler for me than MFC. What I'd like to do is have my existing C++ code run in a WinForm window. I'm having trouble with creating the D3D device. I know how to create a device both in manage and unmanaged code. The problem is how to I get a window of my existing C++ to show in the WinForms? Basically I would need to pass a HWND from the WinForms to my C++ code, or pass the Device from the WinForms to the C++ code and change it to a LPDIRECT3DDEVICE9. Can anyone show me an example? Is this possible? Some Ideas I like not to resort to if possible: 1. Rewrite the C++ code in C#. 1. Port the C++ code to Managed C++. 3. Have a WinForm window and a DirectX window (2 different windows).
Don't shoot! I'm with the science team.....
ernow
ernow
The handle from a Control (e.g. a Form) is available through the Handle property of the control. That's your HWND.

Passing the device might not be a very good option as you need to change it to a pointer while it is a garbage collected reference...

Cheers
OrenGL
OrenGL
Ah that's simple. I'll give it a try.
Thx.
Don't shoot! I'm with the science team.....
Toolmaker
Toolmaker
If your current D3D code is in a C++ DLL, you can always load the DLL and pass the Form.Handle to the DLL. The Form.Handle contains the HWND, but is stored as Int_Ptr or System.Int32.

You could also wrap up your D3D code in a custom control(Using COM and loading it using Interop) and drop this on the form after loading in the control from the OCX/DLL.

Toolmaker
 

Topic Locked

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

Sign in to reply to this topic.