Converting an ATL ActiveX from single threaded to multi threaded apartment?

Verrouillé Converting an ATL ActiveX from single threaded to multi threaded apartment?

  • jeudi 23 août 2012 08:53
     
     

    I have an ActiveX control created in ATL, which was created as a single threaded apartment in VS2006. It being an ActiveX, I wanted to try loading it into IE. It loads into the browser, but crashes when I hover my mouse pointer over it.

    The MSDN websites say that the crash may be because it's single threaded apartment. Is there any way I can convert it to a multi-threaded apartment model without having to re-create the entire project from scratch? (I can convert the project to a VS2010 project too, but need to know how to change the threading model. Currently, I'm not able to see the threading model specification anywhere in the project settings)

    Also, I'd like to ask if it isn't possible to convert the project to multi-threaded apartment, is it logical to write a .NET or C# wrapper which would work on a browser, and load my ActiveX control into it? Would that make sense?


    • Modifié nav9 jeudi 23 août 2012 09:07
    •  

Toutes les réponses

  • jeudi 23 août 2012 13:34
     
     

    In the header file for the control there should be a line that looks something like:

    class ATL_NO_VTABLE CYourClassNameHere :

    public CComObjectRootEx<CComSingleThreadModel>,

    public...

    If you change the "CComSingleThreadModel" to CComMultiThreadModel, I believe it will "convert" the server to multi-threaded.  I'm not 100 percent sure that this is the only change needed, but I believe so.

    The other issue you will face, however, is making sure that the class will behave properly in a multi-threaded environment.  This involves evaluating all of the execution paths to make sure that multiple threads accessing methods at the same time won't mess anything up.

  • jeudi 23 août 2012 22:20
     
     Traitée

    On 8/23/2012 4:53 AM, nav9 wrote:

    I have an ActiveX control created in ATL, which was created as a single threaded apartment in VS2006. It being an ActiveX, I wanted to try loading it into IE. It loads into the browser, but crashes when I hover my mouse pointer over it.

    An ActiveX control must be apartment-threaded, not multi-threaded. Make sure RGS file adds ThreadingModel key with "Apartment" as its default value, under the control's {CLSID} key. If you don't specify ThreadingModel key at all during registration, then your control is considered to be legacy single-threaded, and IE does indeed have trouble with those.


    Igor Tandetnik