Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
C++
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
Posted
Updated 12-Mar-16 2:04am
v4
Comments
Emilio Garavaglia 23-Feb-11 2:09am    
adjusted <pre> tags

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
 
Share this answer
 
v2
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 dont know if there is an encapsulation for that in mfc.
Regards.
 
Share this answer
 
Comments
EricFowler 24-Feb-11 16:05pm    
'Error C2039: 'QueryInterface' : is not a member of 'CAx0ctrl1''. So what do I QI() on?

CAx0Ctrl is derived from CWnd, and has methods for Create(), CreateControl(), GetCLSID(). I have noticed it calls an InvokeHelper() from one of the framework produced functions.
mbue 25-Feb-11 7:33am    
You can use the wizard to creaete a member of your ocx control. The wizard will build the whole class with members (methods and properties) your ocx has. the ocx must have a type library for that. the control site and their functions are as protected memebers encapsulated in CWnd.
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900