Solved

Dynamically loading an activex control

Posted on 1998-08-11
13
369 Views
Last Modified: 2013-11-20
I know that it is possible to instantiate an activex control at runtime by passing the CLSID. Does anyone know any more about this or have a sample???

Thanks
0
Comment
Question by:awhit01
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1320567
You're asking this question in the MFC section, so i am assuming you have visual c installed ...
Take a look into the TSTCON32.EXE source code, which you'll find on your vc++ cd.
It is the 'Test container' in your 'Tools' menu, and it binds dynamically to an user selectable
OCX ... Is that what you're looking for?
0
 

Author Comment

by:awhit01
ID: 1320568
I dont appear to have the code for this but I do know what you mean. Where can i get the source??


0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320569
I currently have no access to my Visual C++ CD - it's installed on the computer in my office.
But i am 100% sure that the source code is provided (i'm using VC 4.0) - search the
CD for 'tstcon.mdp' or 'tstcon32.mdp' or even 'tstcon.mak'.
On of these should be successful ...
Another helpful page could be

http://premium.microsoft.com/msdn/library/techart/msdn_contcntr.htm

just check it out
0
 

Author Comment

by:awhit01
ID: 1320570
Code is not on Visual C++ 4 disc, Visual C++ 5 disc, Platform SDK or MSSDK. Are you sure the code came from there??


0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1320571
When you insert an ActiveX control into a project, Visual C++ generates a wrapper class for it. There are always two Create member functions as follows.

virtual BOOL Create(LPCTSTR lpszClassName,
            LPCTSTR lpszWindowName, DWORD dwStyle,
            const RECT& rect,
            CWnd* pParentWnd, UINT nID,
            CCreateContext* pContext = NULL)
      { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
            const RECT& rect, CWnd* pParentWnd, UINT nID,
            CFile* pPersist = NULL, BOOL bStorage = FALSE,
            BSTR bstrLicKey = NULL)
      { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
            pPersist, bStorage, bstrLicKey); }

Just call it like normal window creation.
0
 

Author Comment

by:awhit01
ID: 1320572
No, the control must have no dependency on the container. The control is user-selectable at runtime and it's methods/properties should be accessibly


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:chensu
ID: 1320573
I see. So call CWnd::CreateControl.

BOOL CWnd::CreateControl( LPCTSTR lpszClass, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );

BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );

0
 

Expert Comment

by:babu_suresh
ID: 1320574
CWnd::CreateControl helps to do this
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320575
And you can call CWnd::InvokeHelper to access its methods and properties.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320576
Also CWnd::GetProperty, CWnd::SetProperty.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320577
Take a look into a visual c generated ocx mapper. You'll see there how the control
gets initialized and how the functions are called.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1320578
>generated ocx mapper
generated OCX wrapper class

0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320579
Sorry - i am in germany and unfortunately it is quite expensive to have access to
the internet here - so i am often a little bit in a hurry :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now