Click here to Skip to main content
13,355,335 members (73,978 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 24 Aug 2005

A COM class (DLL) for embedding an embeddable OLE object

, 20 Jul 2006
Rate this:
Please Sign up or sign in to vote.
A COM class (DLL) that embeds an embeddable OLE object.


Using MFC, we can easily develop an ActiveX container application, but unfortunately, it only works with the doc/view architecture as an executing file. If you want to embed an OLE embeddable object but your program is not an executable program and it has to be a DLL (for example, for many kinds of plug-ins, they work as DLL files), then this article will give you help.

Using the code

It's very simple to use. This COM object has only three methods, Create, Open, and OnSize.

  1. You must declare the interface, and add the include files where it works (note: this COM object will work as a child window).

    In the tester, I added it to CTesterDlg as an element.

    #include "..\emboleobjctrl\emboleobjctrl_i.h"
    IEmbOleObjControl * m_pCtrl;
  2. Initialize the object's pointer to NULL:
    CtesterDlg::CtesterDlg(CWnd* pParent /*=NULL*/)
        :CDialog(CtesterDlg::IDD, pParent)
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
        m_pCtrl = NULL;
  3. Create the instance, and create the window:
    void CtesterDlg::ObBnClickedCreate()
      if(m_pCtrl)   //if the object exists then quit
      HRESULT hr = ::CoCreateInstance(CLSID_EmbOleObjControl, 
                   (void **)&m_pCtrl);
          HWND hWnd;
          //create needs a parameter as the control's container window,
  4. Open the specific file and the specific OLE server:
    void CtesterDlg::OnBnClickedBtnopen()
            AfxMessageBox("please create the control first");
        CString strInfo;
        CWnd *pWnd = GetDlgItem(IDC_EDTPATH);
        _bstr_t bstrInfo(strInfo.GetBuffer());
        static CLSID const clsid_App ={ 0x7b93e267, 0x6bbc, 0x11d4, 
               { 0xa5, 0x4d, 0x0, 0x50, 0xba, 0xdb, 0x14, 0xa3 } };
           //clsid_app : the ole server's clsid
           //bstrInfo: the file's path
  5. When the container window's size changes, call IFoxitPDFControl::OnSize() (for the current case, the container is not sizeable).
  6. Before the container window is destroyed, destroy (release) it.
    void CtesterDlg::OnCancel()

Points of interest

Wrapping the doc/view architecture into a DLL module is not easy since the mainframe window in that architecture works as an overlapped window, it doesn't work as a child window; but here it must work as a child window (strictly, it works as a popup window here). In order to adjust the window's position, there is an additional method exported (OnMove). Even now, there is a problem annoying me, that this COM object can't work with MS-Word correctly. Hope somebody here can correct it to work with any OLE server without problems.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
My name is Wangwanxin, living in beijing,China.since spe,2002 till now,working as a windows software developer,be faimliar with c++/mfc,atl. devotional,faithful,... I'll devote more time here, I'd like to exchange my limited ideas here,open my heart, and then have the whole world. Smile | :)

You may also be interested in...

Comments and Discussions

GeneralQuestion Pin
charfeddine_ahmed10-Jul-06 22:30
membercharfeddine_ahmed10-Jul-06 22:30 
GeneralRe: Question Pin
William.Wang13-Jul-06 0:01
memberWilliam.Wang13-Jul-06 0:01 
GeneralRe: Question Pin
charfeddine_ahmed13-Jul-06 0:53
membercharfeddine_ahmed13-Jul-06 0:53 
GeneralRe: Question Pin
William.Wang13-Jul-06 16:40
memberWilliam.Wang13-Jul-06 16:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 20 Jul 2006
Article Copyright 2005 by William.Wang
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid