Is it possible to pack a WPF window as a COM object

I am trying to use a WPF window from an outdated gtk GUI application that is not user controlled. Is it possible to pack a WPF window (including xaml file) and use it in a C ++ gui application as a regular com object. Do you anticipate any problems or issues with this approach?

If possible, any links or guides or any suggestions on how to do this will be very helpful. Thank.

+3
source share
1 answer

I do not know any online tutorial for this; but that should not be a big problem. I tried to implement smth like this, and it worked fine for me, below is the sequence if the steps I took are:

1.add "user control wpf user" or "wpf custom control" for your solution.

2. Attach the new WPF window class (Add-> Window → ...) to the new project. Then add that wpf ever controls how you like in the new window to check if it works later

3.add a new class and interface to the library project and define it as an example below:

[ComVisible(true)]
[Guid("694C1820-04B6-4988-928F-FD858B95C881")]
public interface ITestWPFInterface
{
    [DispId(1)]
    void TestWPF();
}

[ComVisible(true)]
[Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123F"),
ClassInterface(ClassInterfaceType.None)]
public class TestWPFInterface : ITestWPFInterface
{
    public void TestWPF()
    {
        Window1 form = new Window1();
        form.Show();
    }
}

4. Make your prefab com visible (register for the interop COM key on the Build tab of the project properties) and assign it a strong name (see the signature tab); generate key using sn utility

5. your_wpf_lib.tlb, debug\release

6. ++ ( , ), :

"C:\full_path_to_your_tlb\your_wpf_lib.tlb"

tlh win32.

++:

TestWPFForms::ITestWPFInterfacePtr comInterface(__uuidof(TestWPFForms::TestWPFInterface));
comInterface->TestWPF();

wpf.


, :

COM- .NET # ++

WPF Win32

, ,

+9

Source: https://habr.com/ru/post/1731074/


All Articles