Dynamically loading an activex control

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
awhit01Asked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
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
 
snoeglerCommented:
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
 
awhit01Author Commented:
I dont appear to have the code for this but I do know what you mean. Where can i get the source??


0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
snoeglerCommented:
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
 
awhit01Author Commented:
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
 
awhit01Author Commented:
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
 
chensuCommented:
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
 
babu_sureshCommented:
CWnd::CreateControl helps to do this
0
 
chensuCommented:
And you can call CWnd::InvokeHelper to access its methods and properties.
0
 
chensuCommented:
Also CWnd::GetProperty, CWnd::SetProperty.
0
 
snoeglerCommented:
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
 
chensuCommented:
>generated ocx mapper
generated OCX wrapper class

0
 
snoeglerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.