How to call method of an ActiveX control from inside VC++ project.

kamp007
kamp007 used Ask the Experts™
on
Hi all,

 I have developed an ActiveX control (using VB), which will plot some data for 5 seconds. Now i have written a method that can accept the the time in run time.

Then i inserted the ActiveX by right clicking on dialog box & include ActiveX control, it works fine then i did not see any wrapper classes. (but when i included this control by clicking project->include object-> this activex control, I could see wrapper class created for this but i did not know how to display this in the dialog box.

 And i have no idea of how to call the method there so that the graph is plotted for the new time interval that i pass from inside VC++.

 Thanks in advance

 Kalai
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You have to get the IDispatch pointer to the ActiveX control then call its method.

  ICtrlPtr pCtl;
  IUnknown* pIUnk = NULL;
  if SUCCEEDED(GetDlgControl(IDC_Control,
                             __uuidof(IUnknown),
                            (void**)&pIUnk))
  {
     pCtl = pIUnk;
     pCtl->MethodCall();
  }

IDC_Control is your resource ID for the ActiveX control.

I hope this helps.
Jim

Author

Commented:
Even though i know C++, i am not a experienced VC++ programmer. So I am not sure about what u said. Can you please explain it clearly. And I am sorry i forgot to say that, i inserted the ActiveX by right clicking on dialog box & include ActiveX control, then i did not see any wrapper classes.
Thanks again
Kalai
Commented:
ok.  Well, there are a few ways you can do this.  You can have the wizard generate the wrapper classes or you can use the raw interface pointer for the chart.  The method I showed above uses the interface pointer to the chart.  

To generate the wrapper classes:
From the menu select:
Project
---- Add to Project
-------- Components and Controls
in the dialog select Registered ActiveX Controls
select the control you added to the dialog.
Confirm the classes dialog - add all to your project.
close the dialog.

You'll have to include the control class in your dialog class.
#include "mschart.h"
and create a member variable -
CMsChart* m_pChart;

then call
m_pChart = (CMSChart *) GetDlgItem(IDC_MSCHART1);
m_pChart->Layout() // or whatever function you're calling.

Let me know if this helps.
Jim

Author

Commented:
def that helps. But i read some MFC book and figured out myself about how to pass a pointer to a Control item. But thanks for your reply.
kalai

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial