Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamically loading an activex control

Posted on 1998-08-11
13
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 200 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
 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 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