• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 721
  • Last Modified:

Using AtlAxCreateControl and unloading controls

Hi all,

I am using the ATL function AtlAxCreateControl to create an ActiveX control at run time, using my dialog box as the parent window.

My product requires a functionality that, I must also be able to unload this dynamicaly created ActiveX control at run time. By unloading , I mean , destroying the control window (if it had one) and freeing all the associated resources.

Any comments/suggestions is welcome ?

Thanks in advance


0
saurabh_dasgupta
Asked:
saurabh_dasgupta
1 Solution
 
ShaunWildeCommented:
I'd use CAxWindow::CreateControl/Ex instead it calls AtlAxCreateControl internally and wraps it up in an easy to manipulate object
0
 
saurabh_dasguptaAuthor Commented:
Thanks for the reply. I have just managed to get hold of some code from a MSDN article titled:
"Write ActiveX Controls Using Custom Interfaces Provided by ATL 3.0"

In this article I observed that the approach should be:

(i)Creat an instance of CAxWindow
(ii)Query for the interface IAxWinHostWindow using QueryHost method of CAxWindow
(iii)Use the method CreateControl of IAxWinHostWindow to create the OLE control
(iii)Remember a reference to the IUnknown of the OLE control
(iv)When the time to unload comes, use the IOleObject::Close  method

I am still not able to understand why the OLE control pointer returned from a direct call to AtlAxCreate.. Or CAxWindow wont give me an IOleObject interface when I do a query interface ??? Wheras the IAxWinHostWindow approach is absolutely fine ...!!!

Thanks



0
 
ShaunWildeCommented:
I couldn't say without further investigation but the ATL source code might hold a clue as IAxWinHostWindow is an ATL interface - it seems that as it is a wrapper then a simple QI on the interface would not work so it exposes a method that allows you to access the wrapped object - I hope this answers you question
0
 
Roshan DavisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
 
Computer101Commented:
PAQed, with points refunded (200)

Computer101
E-E Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now