none
.Net ActiveX control does not allow MFC/ATL container to shutdown properly RRS feed

  • Question

  • .Net ActiveX control does not allow MFC/ATL container to shutdown property

    Hello,

    First of all, I just found exactly the same issue reported on this forum:

    http://social.msdn.microsoft.com/Forums/en-US/vbinterop/thread/d24962f3-ec79-4d77-9cac-2c5d46e38667

    Unfortunately it was not answered and finally it was suggested to contact paid support. However I’d like to try to raise this question on common forum one more time because of two reasons:

          • This is very general problem. Happens with absolutely any MFC/ATL based container and any .Net based ActiveX control. I will use only Microsoft examples in the problem description.
          • I think the reason why it happen specified incorrectly during discussion of previously reported issue and we definitely don’t need to check any dump file to get to the bottom of the problem.

    The problem can be demonstrated by using two Microsoft examples:

    1. .Net Active X Control: It was downloaded from here: http://code.msdn.microsoft.com/windowsdesktop/CSActiveX-b86194f8
    2. Container:  http://msdn.microsoft.com/en-us/library/f9adb5t5(v=VS.90).aspx  (Actually I was using source code of TstCon example in VS 2010 to build this application)

    All that has to be done is to start TstCon.exe, insert “CSActiveX.CSActiveXCtrl” and then close the application. After the application disappears, check the process list in Task Manager – TstCon.exe is still there.

    Now explanation of why it happens is relatively simple: .Net control queries bunch of interfaces (IOleIPsite, IDispatch, IAdviseSink) from container’s host site, which naturally increases references count of the host site object, but then, after the container releases all references to the .Net control, it for some reason does not do the same for the container (which is done by any ATL, MFC, VB6 – based ActiveX control). So reference counter does not reach zero and an object associated with the host site never gets deleted.

    In MFC ActiveX host site is implemented by COleClientItem class. In constructor it calls AfxOleLockApp() and in destructor it calls AfxOleUnlockApp(), increasing/decreasing reference counter of the container application.  Since destructor of OleClientItem never gets called, reference counter of the application never reaches zero as well. The application calls AfxOleCanExitApp() , which returns false if reference counter is not zero.  As a result application does not send WM_QUIT message and never exits. The reason it looks like it was closed is because it hides main window before calling AfxOleCanExitApp (weird MFC implementation).

    One more thing: out of all containers applications I have checked, IE seems to exit correctly. My best guess is that it simply ignores the fact that .Net AX control still holding its host site.

    So my question is: is it an unknown bug in .NET implementation or is it a known bug that can’t be fixed. In first case please consider this as a bug report submission, in the other case please give us some explanation of why it happens and can’t be fixed.

    Thanks in advance.

    Thursday, October 11, 2012 8:06 PM

All replies

  • Hi CCC,

    I am trying to involve some other one in this thread, please wait it patiently.

    Our  managed forum is focused on break fix issues that are neither urgent, nor complex. If the issue is urgent to your business, it is recommended that you contact Microsoft Customer Spport Services(CSS) via telephone so that a dedicated Support Professional can assist you in a more efficient manner. Please be advised that contacting phone support will be a charged call. 

    to obtain the phone numbers for specific technology request please take a look at the web site listed below.

    http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS  

    If you are outside the <st1:country-region w:st="on"><st1:place w:st="on">US</st1:place></st1:country-region> please seehttp://support.microsoft.com for regional support phone numbers.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 12, 2012 10:17 AM
    Moderator
  • Thanks Mike. I'll wait. Actually our company is MSDN subscriber so I assume we even can get a free support but for now I'm trying to get an answer on forum as I consider it to be general problem. I'm also not looking for anything like a fix right this second, I'm just trying to understand the nature of this problem to avoid possible issues in the future and make a correct decision.

    A little bit about what we are trying to do. Our company uses MFC container application and a lot of different ATL or VB6 ActiveX controls to display real time information from controllers or archive. We need to add one more component to our system and we just thought it would be a good idea to use .NET. I did not get too deep yet, but I did not find any problems with .NET AX control so far other than described one. In either case we always can go by good old way.

    Best regards

    Dmitry



    Friday, October 12, 2012 5:08 PM
  • Hi Dmitry,

    There are known issues using MFC as container for OLE components like you mentioned. Please use

    https://connect.microsoft.com/VisualStudio/ to file a bug againts latest MFC Library VS2012. This will get Product Groups attention and you can track the progress as well.

    Thanks,

    Gaurav

    Thursday, October 18, 2012 2:11 PM