Unanswered How to unload/unlock the ActiveX (OCX) file from IE process ?

  • Wednesday, June 20, 2012 5:03 AM
     
     

    I have a ActiveX control developed for using it in Internet Explorer. When the page loads, I want to detect that the ActiveX requires an upgrade and then if it is required, open a new window where the upgrade occurs. I have been able to detect the ActiveX using either "new ActiveXObject" or by embedding it in the page (program/declarative) and then call a getVersion function implemented by ActiveX.

    The challenge that I am facing is that when I embed the plugin in the new window for the upgrade to occur. The install prompt is shown but seems after the plugin is downloaded it fails to write to the OCX file and hence popups up the system dialog saying "You must restart your computer before the new settings will take effect ...". So, I understand that this issue occurs because the OCX has been loaded by the IE process when its instance is created in the main page (for detecting upgrade) and now when the upgrade is occuring in the new window, it fails to write to the OCX file as it is already locked.

    What I want to know is that, is there any way I can get the OCX file unlocked from the IE process, when I destroy the last instance of ActiveX Object ? Getting it unlocked from the IE process will help me get my upgrade work seamlessly.


    Note : I have the upgrade already working in the same page. i.e. when I embed the ActiveX in the main page. But my requirement is such that I want to first detect if need a upgrade or not and then open a new window and then upgrade the ActiveX there. So it is important for me to get the ActiveX file (OCX) unlocked from the IE process. The issues applies to all IE versions.

All Replies

  • Thursday, June 21, 2012 12:40 AM
     
     

    If you navigate away from the page that contains your ActiveX, then the ActiveX is closed and released (same cannot be said for the object created in script, there's a GC involved).

    If your implementation of DllCanUnloadNow is correct, then your ActiveX will be unloaded at idle time, in a matter of minutes. If you feel it is not often enough, you can call CoFreeUnusedLibraries, but you need to call the function in the process that loads the ActiveX, which means you need to have another COM object running in the process. If you plan to update the updater COM object too, then you probably want to see if the user can download your ActiveX's installer and just close all IE windows like Adobe does for Flash. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


  • Thursday, June 21, 2012 12:39 PM
     
      Has Code

    Thanks for the reply. I see that I cannot upgrade the plugin in a new window. But I have figured out that it is possible to upgrade it seamlessly after detecting the install/upgrade in the same page.

    So first time embed the ActiveX without CODEBASE to just detect the install/upgrade requirement.

    document.getElementById('pluginObject').innerHTML = "<OBJECT id='ActiveXObj' CLASSID='XXXXX-XXXXXX-XXXXXXX-XXXXXXX-XXXXX'/>" // without CODEBASE
    
    var activeXControl = document.getElementById ('ActiveXObj');
    
    var version = activeXControl.getVersionAPI (); // need to be implemented by the ActiveX Control and return the version.

    Then check the current version vs the version downloaded from server to decide if we require a upgrade.

    Now after detecting depending on the findings, again embed to the same html element with CODEBASE (URL + version) to trigger the install/upgrade.

    document.getElementById('pluginObject').innerHTML = "<OBJECT id='ActiveXObj' CLASSID='XXXXX-XXXXXX-XXXXXXX-XXXXXXX-XXXXX' CODEBASE'<URL>#Version=X.X.X.X'/>" // with CODEBASE to trigger the install/upgrade.