注册免费COM,线程模型,MT.exe和* .RGS脚本

时间:2012-11-26 20:02:29

标签: com manifest mt rgs registration-free-com

我有一个免注册的C ++ COM组件,我使用VS2010使用mt.exe生成清单。一切正常,除了我无法指定我的类使用哪个线程模型。我创建了一个小的repro项目,其生成的清单文件(RGS.dll.embed.manifest)如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 <file name="RGS.dll" hashalg="SHA1">
  <comClass clsid="{4EB506E0-0D9C-4281-9B61-F027376E21C3}" tlbid="{6B48D06F-A84C-4B72-A70F-F1B091789E67}"></comClass>
  <typelib tlbid="{6B48D06F-A84C-4B72-A70F-F1B091789E67}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib>
 </file>
 <comInterfaceExternalProxyStub name="IRgsObject1" iid="{4620CAB8-3E56-42EC-818E-8A55DF9267B7}" tlbid="{6B48D06F-A84C-4B72-A70F-F1B091789E67}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub>
</assembly>

我遇到问题的部分是comClass节点

<comClass clsid="{4EB506E0-0D9C-4281-9B61-F027376E21C3}" 
          tlbid="{6B48D06F-A84C-4B72-A70F-F1B091789E67}"></comClass>

应具有threadingModel属性,如下页“Sxs和注册免费COM激活”示例所示: http://blogs.msdn.com/b/junfeng/archive/2006/04/20/579748.aspx

我知道*.tlb中未指定线程模型,但是根据Sen Harada对mt.exe的MSDN文档的评论,您应该能够在注册脚本文件中指定一个({1}} {1}}) http://msdn.microsoft.com/en-us/library/windows/desktop/aa375649(v=vs.85).aspx

所以我有ATL向导创建的*.rgs文件

*.rgs

所以我将HKCR { NoRemove CLSID { ForceRemove {4EB506E0-0D9C-4281-9B61-F027376E21C3} = s 'RgsObject1 Class' { ForceRemove Programmable InprocServer32 = s '%MODULE%' { val ThreadingModel = s 'Neutral' } TypeLib = s '{6B48D06F-A84C-4B72-A70F-F1B091789E67}' Version = s '1.0' } } } 文件提供给*.rgs

mt.exe

从构建日志中可以看出它已成功解析了C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /out:"Debug\RGS.dll.embed.manifest" /tlb:"Debug\RGS.tlb" /rgs:"RgsObject1.rgs" /dll:"RGS.dll" /manifest Debug\RGS.dll.intermediate.manifest 文件

*.rgs

(特别是“有效GUID !!!”行没有 Valid GUID!!! {4EB506E0-0D9C-4281-9B61-F027376E21C3} Adding entry ClsidTable[{4EB506E0-0D9C-4281-9B61-F027376E21C3}] = RgsObject1 Class CManGenLib.ParseFileContents::Appending class {00000000-0000-0000-0000-000000000000} Processed .RGS file successfully Found type library in file , guid {6B48D06F-A84C-4B72-A70F-F1B091789E67} (contains 2 types) CManGenLib.ProcessTlb::Appending class {6B48D06F-A84C-4B72-A70F-F1B091789E67} Found interface {4620CAB8-3E56-42EC-818E-8A55DF9267B7} 'IRgsObject1' Processed .TLB file successfully Looking for pstub {4620CAB8-3E56-42EC-818E-8A55DF9267B7} (IRgsObject1) 参数到rgs:

我的mt.exe没有threadingModel属性。

这个人是我能找到的唯一一个谈论问题的人,http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/dbab28cd-023f-45b1-be62-7dc71e8d3d9f,他从未找到解决方案,并在生成后编辑了清单。有谁知道mt.exe工具如何使用RGS文件来创建清单,以及我需要做些什么才能让threadingModel从另一端获取?

1 个答案:

答案 0 :(得分:5)

有趣......看起来有些残留的ProgId东西需要在那里让mt.exe感到高兴。具体来说,以下*.rgs

HKCR
{
    AtlObjectProgId.1 = s 'AtlObject Class'
    {
        CLSID = s '{2371607D-284A-4D7C-A6DD-20C15373F43F}'
    }
    NoRemove CLSID
    {
        ForceRemove {2371607D-284A-4D7C-A6DD-20C15373F43F} = s 'AtlObject Class'
        {
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Free'
            }
        }
    }
}

生成以下*.embed.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><file name="ATLProject2.dll" hashalg="SHA1"><comClass clsid="{2371607D-284A-4D7C-A6DD-20C15373F43F}" tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}" threadingModel="Free"></comClass><typelib tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib></file><comInterfaceExternalProxyStub name="IAtlObject" iid="{81A8B3DA-2AFE-4C25-B0ED-CDD777FB01A4}" tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub></assembly>

而以下*.rgs

HKCR
{
    NoRemove CLSID
    {
        ForceRemove {2371607D-284A-4D7C-A6DD-20C15373F43F} = s 'AtlObject Class'
        {
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Free'
            }
        }
    }
}

生成以下*.embed.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><file name="ATLProject2.dll" hashalg="SHA1"><comClass clsid="{2371607D-284A-4D7C-A6DD-20C15373F43F}" tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}"></comClass><typelib tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib></file><comInterfaceExternalProxyStub name="IAtlObject" iid="{81A8B3DA-2AFE-4C25-B0ED-CDD777FB01A4}" tlbid="{92B1424C-0D03-4909-99DC-2A70EFD210D5}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub></assembly>

编辑:它似乎有效,但它只适用于*.rgs文件中的第一个类。例如,以下*.rgs

HKCR
{
    AtlObj1ProgId.1 = s 'AtlObj1 Class'
    {
        CLSID = s '{D15A646A-4F2F-42C2-BA8B-780AABCFB133}'
    }
    AtlObj1ProgId = s 'AtlObj1 Class'
    {       
        CurVer = s 'AtlObj1ProgId.1'
    }
    NoRemove CLSID
    {
        ForceRemove {D15A646A-4F2F-42C2-BA8B-780AABCFB133} = s 'AtlObj1 Class'
        {
            ProgID = s 'AtlObj1ProgId.1'
            VersionIndependentProgID = s 'AtlObj1ProgId'
            ForceRemove Programmable
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Neutral'
            }
            TypeLib = s '{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}'
            Version = s '1.0'
        }
    }

    AltObj2ProgId.1 = s 'AtlObj2 Class'
    {
        CLSID = s '{C208B430-8E12-4C65-AA5A-899F6AB13C4B}'
    }
    AltObj2ProgId = s 'AtlObj2 Class'
    {       
        CurVer = s 'AltObj2ProgId.1'
    }
    NoRemove CLSID
    {
        ForceRemove {C208B430-8E12-4C65-AA5A-899F6AB13C4B} = s 'AtlObj2 Class'
        {
            ProgID = s 'AltObj2ProgId.1'
            VersionIndependentProgID = s 'AltObj2ProgId'
            ForceRemove Programmable
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Neutral'
            }
            TypeLib = s '{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}'
            Version = s '1.0'
        }
    }
}

生成以下*.embed.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><file name="RgsClass2.dll" hashalg="SHA1"><comClass clsid="{D15A646A-4F2F-42C2-BA8B-780AABCFB133}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" threadingModel="Neutral" progid="AltObj2ProgId"><progid>AtlObj1ProgId.1</progid><progid>AltObj2ProgId.1</progid></comClass><comClass clsid="{C208B430-8E12-4C65-AA5A-899F6AB13C4B}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}"></comClass><typelib tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib></file><trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><requestedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel></requestedPrivileges></security></trustInfo><comInterfaceExternalProxyStub name="IAtlObj1" iid="{FF2A4D47-DADA-451E-8125-610643B00FBC}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub><comInterfaceExternalProxyStub name="IAtlObj2" iid="{F9226919-2AB7-4DBE-9F79-092839480351}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub></assembly>

观察到只有第一个CoClass有一个threadingModel(或者就此而言是一个ProgId)。


编辑:成功!以下*.rgs

HKCR
{
    AtlObj1ProgId.1 = s 'AtlObj1 Class'
    {
        CLSID = s '{D15A646A-4F2F-42C2-BA8B-780AABCFB133}'
    }

    NoRemove CLSID
    {
        ForceRemove {D15A646A-4F2F-42C2-BA8B-780AABCFB133} = s 'AtlObj1 Class'
        {
            ProgID = s 'AtlObj1ProgId.1'
            VersionIndependentProgID = s 'AtlObj1ProgId'
            ForceRemove Programmable
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Neutral'
            }
            TypeLib = s '{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}'
            Version = s '1.0'
        }
    }
}

HKCR
{
    AltObj2ProgId.1 = s 'AtlObj2 Class'
    {
        CLSID = s '{C208B430-8E12-4C65-AA5A-899F6AB13C4B}'
    }

    NoRemove CLSID
    {
        ForceRemove {C208B430-8E12-4C65-AA5A-899F6AB13C4B} = s 'AtlObj2 Class'
        {
            ProgID = s 'AltObj2ProgId.1'
            VersionIndependentProgID = s 'AltObj2ProgId'
            ForceRemove Programmable
            InprocServer32 = s '%MODULE%'
            {
                val ThreadingModel = s 'Neutral'
            }
            TypeLib = s '{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}'
            Version = s '1.0'
        }
    }
}

生成以下*.embed.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><file name="RgsClass2.dll" hashalg="SHA1"><comClass clsid="{D15A646A-4F2F-42C2-BA8B-780AABCFB133}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" threadingModel="Neutral" progid="AtlObj1ProgId"><progid>AtlObj1ProgId.1</progid></comClass><comClass clsid="{C208B430-8E12-4C65-AA5A-899F6AB13C4B}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" threadingModel="Neutral" progid="AltObj2ProgId"><progid>AltObj2ProgId.1</progid></comClass><typelib tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" version="1.0" helpdir="" flags="HASDISKIMAGE"></typelib></file><trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><requestedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel></requestedPrivileges></security></trustInfo><comInterfaceExternalProxyStub name="IAtlObj1" iid="{FF2A4D47-DADA-451E-8125-610643B00FBC}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub><comInterfaceExternalProxyStub name="IAtlObj2" iid="{F9226919-2AB7-4DBE-9F79-092839480351}" tlbid="{85D8EC5E-3C24-4151-83D9-34CCE9A1E534}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub></assembly>