如何访问WinForm的ActiveX控件在MFC中没有CLR [英] How to Access Winform ActiveX Control in MFC No CLR

查看:368
本文介绍了如何访问WinForm的ActiveX控件在MFC中没有CLR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目的四个项目


  1. C#DLL暴露出通过互操作COM接口

  2. <李于彼> WPF控件其中包含1
    暴露的类的实例
  3. 一个WinForm的ActiveX哪些主机使用ElementHost的2 WPF控件

  4. 的MFC对话框应用程序使用3
  5. 控制
  1. C# DLL Which Exposes a COM Interface via Interop
  2. A WPF Control which contains an Instance of an exposed class in 1
  3. A Winform ActiveX which hosts the WPF control in 2 using ElementHost
  4. An MFC Dialog Application using the Control from 3

在WinForm的ActiveX(3)通过函数暴露1类的实例在第2祝从通过的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.

我可以在MFC应用程序通过COM访问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.

所以,问题是我怎么弄一个指针从MFC的应用程序中不使用CWinFormControl 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进程id属性。

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

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

接下来抓住IUnknown和的QueryInterface为COM对象您需要

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++

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆