Question

I have been working for quite a while on a simple graphics engine in C++ using Direct3d 11. I have decided to try and build a GUI just for fun, and after reading some on WPF, I really got fond of it. Thing is, i'm not sure if what I want to do is even possible.

What I would like to do is to load my engine DLL in a WPF application, and use the DX device inside a portion of the WPF window. Basically, what I want to do is similar to a map editor( where the main window has a bunch of controls and a child window that contains the render area - the device ), but instead of converting my engine to XNA, I'd like to use the already working C++ code with WPF. Is that possible?

Also, I have tried just for practice to create a window with Win32 and attach the device to it. It was a simple matter of just assigning the window HWND to the device upon device creation. I assume its the same with a WPF window, or am I wrong? Thank's for reading :)

Edit: Forgot to mention that I'm a complete novice with C#, but I do know you can import a C++ DLL and use its functions, I'm just no sure about the device - wpf window interaction.

Was it helpful?

Solution 2

WPF mainly works with managed code. Managed code means most of the things are taken care by garbage collector. And as I can see from your post You want to integrate C++ dll which is unmanaged code. It is not so simple using C++ library in WPF but not impossible. C# provides many other aspects to handle these kind of scenarios.

You will have to take a look about Interoperability and unmanaged code. Have a look on below link: Sample Project

OTHER TIPS

For the WPF/D3D11 interop, have a look at WPFDXInterop that was written by a Microsoft engineer. This allows you to have a D3D render target inside a WPF window, with proper interaction. There's a sample project at the link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top