<tfoot id='1UpDx'></tfoot>
  • <i id='1UpDx'><tr id='1UpDx'><dt id='1UpDx'><q id='1UpDx'><span id='1UpDx'><b id='1UpDx'><form id='1UpDx'><ins id='1UpDx'></ins><ul id='1UpDx'></ul><sub id='1UpDx'></sub></form><legend id='1UpDx'></legend><bdo id='1UpDx'><pre id='1UpDx'><center id='1UpDx'></center></pre></bdo></b><th id='1UpDx'></th></span></q></dt></tr></i><div id='1UpDx'><tfoot id='1UpDx'></tfoot><dl id='1UpDx'><fieldset id='1UpDx'></fieldset></dl></div>
      <bdo id='1UpDx'></bdo><ul id='1UpDx'></ul>

      <small id='1UpDx'></small><noframes id='1UpDx'>

      1. <legend id='1UpDx'><style id='1UpDx'><dir id='1UpDx'><q id='1UpDx'></q></dir></style></legend>

        是否可以将 WPF 窗口打包为 COM 对象

        Is it possible to package WPF window as COM Object(是否可以将 WPF 窗口打包为 COM 对象)

          <small id='qEDHQ'></small><noframes id='qEDHQ'>

            <tfoot id='qEDHQ'></tfoot>

            <i id='qEDHQ'><tr id='qEDHQ'><dt id='qEDHQ'><q id='qEDHQ'><span id='qEDHQ'><b id='qEDHQ'><form id='qEDHQ'><ins id='qEDHQ'></ins><ul id='qEDHQ'></ul><sub id='qEDHQ'></sub></form><legend id='qEDHQ'></legend><bdo id='qEDHQ'><pre id='qEDHQ'><center id='qEDHQ'></center></pre></bdo></b><th id='qEDHQ'></th></span></q></dt></tr></i><div id='qEDHQ'><tfoot id='qEDHQ'></tfoot><dl id='qEDHQ'><fieldset id='qEDHQ'></fieldset></dl></div>

          1. <legend id='qEDHQ'><style id='qEDHQ'><dir id='qEDHQ'><q id='qEDHQ'></q></dir></style></legend>

              <tbody id='qEDHQ'></tbody>
                • <bdo id='qEDHQ'></bdo><ul id='qEDHQ'></ul>

                  本文介绍了是否可以将 WPF 窗口打包为 COM 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用传统 c++ 非托管 gtk gui 应用程序中的 WPF 窗口.是否可以打包 WPF 窗口(包括 xaml 文件)并在 c++ gui 应用程序中将其用作常规 com 对象.您预见到这种方法有什么问题或问题吗?

                  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.

                  推荐答案

                  我不知道网上有什么教程可以做到这一点;但这根本不是什么大问题.我已经尝试过像这样实现 smth,它对我来说效果很好,下面是我完成的步骤的顺序:

                  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.向您的解决方案添加wpf 用户控件"或wpf 自定义控件"库.

                  1.add a "wpf user control" or "wpf custom control" library to your solution.

                  2.在新项目中添加一个新的 WPF Window 类(Add->Window->...).然后将您喜欢的任何 wpf 控件添加到新窗口中,以便稍后检查它是否有效

                  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.向库项目中添加新的类和接口,并像下面的例子一样定义它:

                  3.add new class and interface to the library project and define it like 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. 使您的程序集 com 可见(在项目属性的 Build 选项卡中注册 COM 互操作键)并为其分配一个强名称(请参阅签名选项卡);使用 sn 工具生成密钥

                  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.完成以上所有操作后,您将在 debug elease 文件夹中生成 your_wpf_lib.tlb 文件

                  5.Once all above done you going to have a your_wpf_lib.tlb file generated in the debug elease folder

                  6.在你的 c++ 应用程序中(我猜你有它的源代码并且可以重新编译),添加以下行:

                  6.In your c++ application (I guess you have sources for it and can recompile), add following line:

                  进口"C:full_path_to_your_tlbyour_wpf_lib.tlb"

                  import "C:full_path_to_your_tlbyour_wpf_lib.tlb"

                  这应该会在您的 win32 项目调试输出文件夹中生成适当的 tlh 文件.

                  this should generate appropriate tlh file in the your win32 project debug output folder.

                  7.现在您可以从 c++ 代码中调用您的表单了:

                  7.now you can call your form from the c++ code:

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

                  这应该会显示您的 wpf 表单.

                  this should show your wpf form.

                  另外我相信下面的链接可能对你有用:

                  Also I believe links below might be useful for you:

                  从非托管 C++ 代码调用托管 .NET C# COM 对象

                  WPF 和 Win32 互操作概述

                  希望这会有所帮助,问候

                  hope this helps, regards

                  这篇关于是否可以将 WPF 窗口打包为 COM 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                    <tbody id='CWw3v'></tbody>

                    <bdo id='CWw3v'></bdo><ul id='CWw3v'></ul>

                    <small id='CWw3v'></small><noframes id='CWw3v'>

                    1. <i id='CWw3v'><tr id='CWw3v'><dt id='CWw3v'><q id='CWw3v'><span id='CWw3v'><b id='CWw3v'><form id='CWw3v'><ins id='CWw3v'></ins><ul id='CWw3v'></ul><sub id='CWw3v'></sub></form><legend id='CWw3v'></legend><bdo id='CWw3v'><pre id='CWw3v'><center id='CWw3v'></center></pre></bdo></b><th id='CWw3v'></th></span></q></dt></tr></i><div id='CWw3v'><tfoot id='CWw3v'></tfoot><dl id='CWw3v'><fieldset id='CWw3v'></fieldset></dl></div>
                            <legend id='CWw3v'><style id='CWw3v'><dir id='CWw3v'><q id='CWw3v'></q></dir></style></legend>
                          • <tfoot id='CWw3v'></tfoot>