Solved

Dynamically loading an activex control

Posted on 1998-08-11
13
376 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 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