[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

Using ActiveX in non-MFC app

I have a windows application developed in C++ (not using MFC).  I have been charged with adding various functionality to this application.  Many of the things I need to add are things that have already been developed as ActiveX or OLE controls.  I have found documentation about how to add ActiveX container support manually to an MFC-based application, but that obviously does me no good.  Can anyone help me or point me to online help on including ActiveX support in a NON-MFC windows application?
0
willman
Asked:
willman
1 Solution
 
Tommy HuiCommented:
You have two choices in terms of books: Inside ActiveX Controls and Inside OLE are the best books I've seen that covers ActiveX and OLE stuff without MFC.

But ultimately, it is a matter of knowing the interfaces and supporting those interfaces. You can also check out the OLE programming reference manuals.
0
 
shrifCommented:
Here are your options.  You can purchase a toolkit to do this for you from Integroup at http://www.intergrouptech.com/prodinfo.html.  They are fairly expensive, but the toolkit does exactly what you need -- provide ActiveX containment to a non-MFC application.  They'll also give you a good idea as to the complexity of such a project.
The next option is to write it yourself.  You should get a copy of "Inside ActiveX Controls", "Inside COM" and "ActiveX Web Controls".  Then get the ActiveX SDK and look up under containment.  This document will tell you which interfaces you need to support.  Basically, an ActiveX control is an OLE compound-document that's in process and is embedded and supports properies using Automation and source methods called events.  So you should start with creating an regulard OLE container (one that can contain Excel, for instance), as that is better documented.  You can use "Inside OLE" for this.  OLE Controls (aka OCX's or ActiveX controls) have additional interfaces that you need to support such as handling events and notifications.
For further reading on the subject see the following sites:
See "How to write an OCX container " at
    http://www.neca.com/~vmis/
Also, "OLE Control Containers" at
    http://www.wrox.com/wrox/books/923.htm.
The MSDN has an article and sample called CPATRON, which is a modified version of the PATRON client application from "Inside OLE".

Honesly, though, this is a huge task.  I don't recommend that you do this in plain C.  If you are not going to use the Intergroup stuff mentioned above, then you should use MFC.  Don't think that just because your current application is not MFC, that you can't use MFC with it.  I had the same situation where I had a C++ Win32 application to which I needed to add ActiveX Control containment support.  I simply added MFC to the project and only used MFC in those few source files.  
You just create a global variable of type CWinApp, as in:
CWinApp      theApp;
and then call AfxWinInit() from your WinMain.  That's all there is to using MFC from a non-MFC application.  In addition, you should call       AfxEnableControlContainer();
from WinMain to enable ActiveX control containment.

You can use Class-Wizard to wrap existing controls with C++ classes as is, or you can drag and drop the ActiveX controls on CDialog's or CFormView's.

Good luck
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now