Reloading an ActiveX control

Posted on 2006-04-27
Last Modified: 2013-11-18
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?
Question by:GENTP
    LVL 8

    Expert Comment

    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 ?
    LVL 2

    Accepted Solution

    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();

    LVL 5

    Author Comment

    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.
    LVL 2

    Expert Comment

    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

    LVL 5

    Author Comment

    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.
    LVL 2

    Expert Comment

    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.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now