从MFC客户端调用ActiveX方法 [英] Calling ActiveX method from MFC client

查看:89
本文介绍了从MFC客户端调用ActiveX方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的概念验证ActiveX控件,并将其命名为AX0。我用蜥蜴给它一个方法,我们的老朋友foo()。我已将控件放在一个对话框中,并再次使用lizard创建一个变量ctrlAx,它是对话框类的成员。我编译并运行,控件出现在对话框中。生活很美好。

现在,我想打电话给foo()。 h * ll怎么做?我需要得到一个界面指针...但是要什么,以及如何?

这是我的调度图。

I have created a very simple proof of concept ActiveX control, and named it AX0. I have used the lizard to give it a method, our old friend foo(). I have placed the control in a dialog box and used the lizard again to create a variable, ctrlAx, which is a member of the dialog class. I compile and run, and the control appears in the dialog. Life is good.
Now, I want to call foo(). How the h*ll to do that? I need to get an interface pointer ... but to what, and how?
Here is my dispatch map.

BEGIN_DISPATCH_MAP(CAX0Ctrl, COleControl)
    DISP_FUNCTION_ID(CAX0Ctrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CAX0Ctrl, "foo", dispidfoo, foo, VT_I4, VTS_I4)
    DISP_FUNCTION_ID(CAX0Ctrl, "bar", dispidbar, bar, VT_I4, VTS_NONE)
END_DISPATCH_MAP()

I already created the ActiveX method, need to know how to call it. 

Thanks loads

Eric

推荐答案

给出MFC和ATL之间的选择 - 我使用ATL实现我的ActiveX控件(OleControl)。



MFC的创建是为了满足完全不同的需求,而ATL是专门为帮助您创建而创建的ActiveX控件和其他COM组件。



如果您可以访问 C ++ Builder [ ^ ] - 使用它 - 它将为您节省大量时间。 VCL是一个**更好的类库,你可能会在MFC中实现你的解决方案所需的20%-30%的时间内完成你的工作。



另一种方法是使用C ++ / CLI或C#来实现您的解决方案。 MFC从16位Windows开始就一直在我们这里,它确实很久了。



最好的问候

Espen Harlinn
Given the choice between MFC and ATL - I'd use ATL to implement my ActiveX Control (OleControl).

MFC was created to cater for entirely different needs, while ATL was specifically created to help you create ActiveX controls and other COM components.

If you have access to C++ Builder[^] - use that - it will save you a lot of time. VCL is a **much** better class library, you will probably get your job done in 20%-30% of the time required to implment your solution in MFC.

An other alternative is to use C++/CLI or C# to implment your solution. MFC has been with us since 16-bit Windows, and it's decidedly getting long in the tooth.

Best regards
Espen Harlinn


IDispatch*  pdisp;
if(S_OK==ctrlAx->QueryInterface(IID_IDispatch,(void**)&pdisp))
{
  LPOLESTR    an[1] = { L"foo" };
  DISPID      ad[1] = { 0 };

  if(S_OK==pdisp->GetIDsOfNames(IID_NULL,an,1,0,ad)
  {
    DISPPARAMS  arg = { 0,0,0,0 };
    VARIANT      ret = { VT_EMPTY; };
    if(S_OK==pdisp->Invoke(ad[0],IID_NULL,0,DISPATCH_METHOD,&arg,&ret,0,0))
    {
      VariantClear(&ret);
    }
  }

  pdisp->Release();
}



i不知道mfc中是否有封装。

问候。


i dont know if there is an encapsulation for that in mfc.
Regards.


请更正我如果你错了。我对这个疑问的想法是你有一个基于dlg的应用程序并创建了一个名为Ax0的容器。从那里你必须调用activex应用程序fn,foo。在这种情况下,请执行以下操作:

创建包含foo的activex方法。并在click事件上调用该方法。
Please correct me if you are wrong. My idea about the doubt is that you have a dlg based application and created a container called Ax0. And from there you have to invoke the activex application fn, foo. In that case do as follows:
Create activex method in which you include foo. And call that method on the click event.


这篇关于从MFC客户端调用ActiveX方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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