Reloading an ActiveX control

I have an ATL ActiveX control that works, but it's crashing every time I hit reload because the software doesn't appear to exit entirly before running through the initalization again.

The WM_DESTROY event runs, but it imidatly starts up with WM_INITDIALOG again before quitting.

How do I make the plugin fully exit, and then re-launch when the user hits reload in the browser?
Who is Participating?
U must make sure u destroy ur control correctly

1) check/debug your main ATL class destructor.
u may be doing something wrong there.

2) if u have threads running, make sure to stop them.

3) unload loaded DLLs

4) do u implement InPlaceActivate & InPlaceDeactivate method ?
see IOleInPlaceObjectWindowlessImpl && CComControlBase for details


HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect = NULL)
      return CComControlBase::InPlaceActivate(iVerb, prcPosRect);

HRESULT InPlaceDeactivate(void)
       // u may closeThreads here
      return IOleInPlaceObjectWindowlessImpl<CUrClassControl>::InPlaceDeactivate();

Dariusz DziaraProgrammerCommented:
I am a little bit confused.

1. "How do I make the plugin fully exit, and then re-launch when the user hits reload in the browser?" - do you use the control on some web page ?

2. Or maybe in dialog - "WM_INITDIALOG" ?

If you use different control will everything be OK ?
GENTPAuthor Commented:
I'm still trying to figure out how to do suggestions 1, 2, and 3.  Can you possibly help me out further with them?  4 on the other hand gives me errors when I try to add the functions you suggested.

error C2695: 'Cax3DPlugin::InPlaceDeactivate': overriding virtual function differs from 'ATL::IOleInPlaceObjectWindowlessImpl<T>::InPlaceDeactivate' only by calling convention

Now I did try calling InPlaceDeactivate(); in my WM_DESTROY function, but that didn't seem to work either.  It still doesn't cause the software to fully exit and re-launch.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

1) do u know how to debug ur activeX ?
u need to place a breakpoint at the start of ur destructor,
then iterate each line with F10 until a line make ur activeX crash.
To enter a function call, press F11

2) are u running threads made with CreateThread function ?
if no, u shouldn't care about that one.

3) are u loading libraries with LoadLibrary function ?
if no, all is ok.

4) correction :

u should have in ur header :

and in ur cpp file :
STDMETHODIMP Cax3DPlugin::InPlaceDeactivate(void)
      return IOleInPlaceObjectWindowlessImpl<Cax3DPlugin>::InPlaceDeactivate();

u may debug / trace this line too

GENTPAuthor Commented:
1) yeah I know that much
2) I wasn't sure.  I'm converting a large code base and it looks like there are threads, but they're all handled properly.
3) Yes that is happening.  If things are working right now, would they be leaking?
4) InPlaceDeactivate doesn't seem to change anything.
ok, try to disable/enable ur code incrementally.

- disable all but activeX base
- check it runs and quits normally
- then activate little part or level of ur code and check it runs and quits ok.

I can't tell u more without ur whole source project.
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.