locked
Threading model in registration-free COM manifest

    Question

  • Hi,

    Apparently, mt.exe generates incomplete manifest for COM aimed to use as registration-free COM.

    I create manifest this way:

    mt -nologo -tlb:MyCOM.tlb -dll:MyCOM.dll -out:MyCOM.tlb.manifest

    Then, I add MyCom.tlb.manifest to a client project (.exe) in Manifest Tool -> Input and Output - > Additional Manifest Files.

    Everything works well with simple single-threaded client, but it does not work with multi-threaded ones. In the latter case, it leads to deadlock during activation, in DoSTApartmentCreate (similar to the one described in Identify deadlock through the hwnd handler). If MyCOM.dll is registered, it works well with both kinds of clients. So, only the registration-free use of MyCOM.dll leads to the deadlock.

    During investigation of the problem, I noticed the MyCOM.tlb.manifest generated by the mt.exe does not include threading model specification. There is no threadingModel attribute added. There is comment below the MSDN reference of the mt.exe confirming this issue:

               mt.exe makes a manifest contatining CoClasses with -dll option, but it's incomplete. It doesn't include the COM threading model, so if you just use the manifest, you face a problem on multi-threading code. This is caused because DLLs doesn't contain the threading model while RGS contains. The threading model is specified with -rgs, so I recommend to use it.

    Unfortunately, there is no reference to documentation explaining how to prepare such .RGS file to generate manifest for registration-free COM. Neither the comment explains how to prepare such file.

    Where can I find a minimal example of such .RGS file suitable for registration-free COM use case?

    Could anyone complete the comment and explain how to cook such  .RGS?


    • Edited by mloskot Tuesday, August 14, 2012 11:11 AM Format
    Thursday, August 09, 2012 4:00 PM

Answers

  • Hi Damon,

    Thank for your response. I don't use RGS scripts in my projects, so I decided to go for different fix.

    I simply use Unix command sed to add missing threadingModel attribute:

    sed.exe -i "s/<comClass clsid=/<comClass threadingModel=\"Apartment\" clsid=/g" MyCOM.tlb.manifest
    I run this command durign one of build events.

    Tuesday, August 14, 2012 11:09 AM

All replies

  • Hi mloskot,
    I have read the Dev Center page and the comments you mentioned in your post.
    As far as I know, RGS files are created by the ATL wizards. When you open an ATL project, you can find it in the resource file folder in Solution Explorer window. It is used for doing registrations. 
    If you want to use it, add “[-rgs:<file1.rgs>]” to the command line.
    Have you tried as I describe above? If you have further questions, or if I misunderstood what you mean, please let me know, thanks!
    Regards,
    Damon

    Damon Zheng [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 14, 2012 8:57 AM
    Moderator
  • Hi Damon,

    Thank for your response. I don't use RGS scripts in my projects, so I decided to go for different fix.

    I simply use Unix command sed to add missing threadingModel attribute:

    sed.exe -i "s/<comClass clsid=/<comClass threadingModel=\"Apartment\" clsid=/g" MyCOM.tlb.manifest
    I run this command durign one of build events.

    Tuesday, August 14, 2012 11:09 AM
  • Hello mloskot,

    Would you like to tell me how you getting on with the other fix? Does it work fine? I would recommend you to share your detailed solution and results here. It can be a good reference for others. Thanks in advance.

    Regards,

    Damon


    Damon Zheng [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 16, 2012 9:31 AM
    Moderator
  • Hi Damon,

    I have a huge solution with large number of projects and I don't use ATL Wizards to define and manage implementation of COM servers and objects. So, I'm not really interested in figuring out how to get the RGS scripts working to solve the missing threadingModel attribute. The sed-based fix is very simple, easy to apply, and does the job for me.

    IMO, explanation on how to use RGS to correct mt.exe output belong to the MSDN documentation and should be provided by Microsoft.

    Mat

    • Edited by mloskot Thursday, August 16, 2012 10:21 AM
    Thursday, August 16, 2012 10:18 AM