Provided the COM reference counting works correctly in your app, you could try forcing to unload the no-longer-in-use ActiveX DLL with CoFreeUnusedLibrariesEx
.
How to unload ActiveX's ocx without terminating main application to allow the ocx to be overwritten?
-
29-06-2022 - |
Pergunta
I have ActiveX
controls implemented in VB6
and are instantiated inside MFC42
application.
I have a tree view structure on the left panel of the application and when different items in the tree are selected, different ActiveX
are loaded accordingly on the right panel to display the details of the selected item.
Whenever I want to modify the VB
code for the ActiveX
, I will need to restart the application. This greatly interrupts the development flow since the application starts pretty slowly.
In some ActiveX
we have dummy code/data to allow the ActiveX
to be executed inside Internet Explorer, which is faster to load, but not all of our ActiveX
have it.
I am expecting that when I click different item in the tree view, the previous ActiveX
is unloaded and I can overwrite it with a new version.
If the ActiveX has never been instantiated/displayed, I am able to replace the ocx
while the application is still running.
I searched in the internet and found two articles on ActiveX
, both of them suggest that the proper way to clean up is to:
m_pControl = new CWnd;
m_pControl->CreateControl(strControlProgid,
"",
WS_VISIBLE,
rc,
this,
5000,
NULL,
FALSE,
NULL);
// ...
m_pControl->DestroyWindow();
delete m_pControl;
The ActiveX
s we have are already destroyed using this method but I still need to exit the application in order to overwrite the ocx
.
EDIT:
Alternatively, for VC++ 6 (with MFC42), instead of CoFreeUnusedLibrariesEx
which is mentioned by Noseratio in his answer; I can use CoFreeUnusedLibraries
which will work without delay for Single Threaded Apartement (STA).
Solução