问题描述
我创建了一个非常简单的概念验证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
推荐答案
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.
这篇关于从MFC客户端调用ActiveX方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!