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

      <small id='4sHNt'></small><noframes id='4sHNt'>

      <legend id='4sHNt'><style id='4sHNt'><dir id='4sHNt'><q id='4sHNt'></q></dir></style></legend>
      • <bdo id='4sHNt'></bdo><ul id='4sHNt'></ul>

      1. 如何在 MFC No CLR 中访问 Winform ActiveX 控件

        时间:2023-05-20

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

                  <tbody id='zCMZ5'></tbody>

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

              • <legend id='zCMZ5'><style id='zCMZ5'><dir id='zCMZ5'><q id='zCMZ5'></q></dir></style></legend>

                • <bdo id='zCMZ5'></bdo><ul id='zCMZ5'></ul>
                • <tfoot id='zCMZ5'></tfoot>
                  本文介绍了如何在 MFC No CLR 中访问 Winform ActiveX 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我的项目由四个项目组成

                  My Project Consists of Four Items

                  1. 通过互操作公开 COM 接口的 C# DLL
                  2. 一个 WPF 控件,其中包含 1 中公开类的实例
                  3. 使用 ElementHost 承载 WPF 控件 2 的 Winform ActiveX
                  4. 使用来自 3 的控件的 MFC 对话框应用程序

                  Winform ActiveX (3) 通过 2 中的函数从 1 公开类实例.我希望通过 ActiveX 从 MFC 对话框应用程序访问该类实例.我环顾四周,发现您可以使用 CWinFormControl 做到这一点.但是我不能使用/clr 重新编译 MFC 应用程序.因此我不能使用 CWinFormControl.

                  The Winform ActiveX (3) exposes the class instance from 1 via a function in 2. I wish to access this class instance from the MFC dialog application through the ActiveX. I have looked around and found you can do this using CWinFormControl. However I am not at liberty to recompile the MFC app using /clr. Therefore I cannot use CWinFormControl.

                  我可以通过 COM 从 MFC 应用程序访问 1 中的类并运行所有函数等,但是该类是不同的实例,因为 DLL 是在其自己的空间中加载的.

                  I can access the class in 1 via COM from the MFC app and run all the functions etc however the class is a different instance as the DLL is loaded in its own space.

                  ActiveX 运行良好,可以很好地显示所有 WPF 数据.

                  The ActiveX works well and displays all the WPF data nicely.

                  所以问题是如何在不使用 CWinFormControl 的情况下从 MFC 应用程序中获取指向 ActiveX 控件的指针?

                  So the question is how do I get a pointer to the ActiveX control from within the MFC app without using CWinFormControl?

                  我尝试从 ActiveX 导入 TLB 并尝试在类向导中为其创建变量",但它报告 TLB 不可用.我也尝试通过手动创建变量直接创建 DDX 条目,但 DDX 不允许指针.

                  I have tried importing the TLB from the ActiveX and attempting to create a "Variable" for it in the Class wizard but it reports that the TLB is unavailable. I have also tried directly creating a DDX entry by manually creating a variable but DDX doesn't allow pointers.

                  有什么想法吗?

                  推荐答案

                  问题基本上是尝试在 MFC 中访问 Winform ActiveX 控件,而无需使用 clr 或托管 C++.

                  The Question is basically trying to access a Winform ActiveX Control in MFC without having to use clr or managed C++.

                  对于任何对此问题的答案感兴趣的人来说,我是如何解决它的.首先,您必须动态创建 ActiveX 并将其放置在您自己的位置.

                  For anyone interested in the answer to this question here is how I solved it. First off you have to dynamically create the ActiveX and place it your self.

                  在您的 MFC 对话框标题中添加一个 CWnd

                  In Your MFC Dialog header add a CWnd

                     CWnd m_MyActiveX;
                  

                  在您的 MFC Cpp 中动态创建控件

                  In your MFC Cpp dynamically create the Control

                     m_MyActiveX.CreateControl("MyActiveX.ProgId","",WS_VISIBLE,prect,this,5000);
                  

                  注意:您可以在 Winform ActiveX 属性中找到 progid

                  NOTE: you can find the progid in your Winform ActiveX attributes

                  [ProgId("MyActiveX.ProgId")]
                  [ClassInterface(ClassInterfaceType.AutoDispatch)]  
                  

                  接下来为您需要的 COM 对象获取 IUnknown 和 QueryInterface

                  Next Grab the IUnknown and QueryInterface for the COM Object You need

                  IOleObjectPtr pOleObj(m_MyActiveX.GetControlUnknown ());
                  if (pOleObj != NULL) 
                  {
                      MyCOMObject::IWpfHostPtr host;
                      pOleObj.QueryInterface(__uuidof(MyCOMObject::IWpfHostPtr),&host);
                  
                      MyCOMWPFControl::IWpfControl wpf;
                      host->GetWpfControl ( &wpf );
                  
                      MyInternalCOMObject::ICoolObject internal;
                      wpf->GetInternalObject ( &internal );
                  
                      internal->AndAPartridgeInaPearTree ();
                   }
                  

                  注意:实际的 Winform ActiveX 必须派生自某个已知接口

                  NOTE: The Actual Winform ActiveX must derive from some known Interface

                  public partial class WpfHost : UserControl, IWpfHost 
                  

                  使用此技术,您可以成功地将 WPF 控件托管在旧版 MFC 应用程序上,并通过 COM 与它们进行通信,而无需使用托管 C++

                  Using this Technique you successfully host WPF Controls on your Legacy MFC Applications and communicate with them via COM without resorting to Managed C++

                  这篇关于如何在 MFC No CLR 中访问 Winform ActiveX 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 MFC 应用程序中托管 WPF 表单 下一篇:NUnit 预期异常

                  相关文章

                  • <bdo id='Do3dt'></bdo><ul id='Do3dt'></ul>
                • <small id='Do3dt'></small><noframes id='Do3dt'>

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