I am trying to use a WPF window from a legacy c++ unmanaged gtk gui application. Is it possible to package the WPF window (including the xaml file) and use it in the c++ gui application as a regular com object. Do you foresee any issues or problems with this approach?
If possible any links or tutorials or any suggestions on how to do it will be very helpful. Thanks.
I'm not aware of any tutorials online for doing this; but it shouldn't be a big problem at all. I've tried implementing smth like this and it worked fine for me, below is sequence if steps I've done:
1.add a "wpf user control" or "wpf custom control" library to your solution.
2.add a new WPF Window class (Add->Window->...) into the new project. Then add what ever wpf controls you like to your new window just to check if it works later
3.add new class and interface to the library project and define it like an example below:
4.make your assembly com visible (Register For COM interop key in the Build tab of the project properties) and assign a strong name to it (see signing tab); generate key with sn utility
5.Once all above done you going to have a your_wpf_lib.tlb file generated in the debug\release folder
6.In your c++ application (I guess you have sources for it and can recompile), add following line:
this should generate appropriate tlh file in the your win32 project debug output folder.
7.now you can call your form from the c++ code:
this should show your wpf form.
Also I believe links below might be useful for you:
Calling Managed .NET C# COM Objects from Unmanaged C++ Code
WPF and Win32 Interoperation Overview
hope this helps, regards