关于ATL的rgs文件

使用ATL向导的话,会在resource中产生一个rgs的注册脚本文件放在"REGISTRY"目录中用来注册组件,会在程序中通过函数DECLARE_REGISTRY_RESOURCEID(IDR_OPCSERVER)使用,IDR_OPCSERVER就是向导产生的资源文件的ID,当服务器调用CComModule::RegisterServer()时,便会使用这些脚本来载入注册表的设置,并在调用CComModule::UnregisterServer()时移除它们。

例子如下

HKCR
{
FactorySoft.myShell.1 = s 'FactorySoft myShell'
{
    CLSID = s '{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}'
}
FactorySoft.myShell = s 'FactorySoft myShell'
{
    CLSID = s '{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}'
        OPC
        {
            Vendor = s 'FactorySoft, Inc'
        }
}
NoRemove CLSID
{
    ForceRemove {C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F} = s 'FactorySoft myShell'
    {
      ProgID = s 'FactorySoft.myShell.1'
      VersionIndependentProgID = s 'FactorySoft.myShell'
      LocalServer32 = s '%MODULE%'
      {
        val ThreadingModel = s 'both'
      }
    }
}
NoRemove AppID
{
    ForceRemove {C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F} = s 'FactorySoft myShell'
}
}

①文件完全按照注册表结构定义
②HKCR表示HKEY_CLASS_ROOT
③对每一个结点,如果无val前缀,表示为一个注册表结点,如果为val定义,则为一个注册表值项
④NoRemove和ForceRemove选项用在卸载时使用,分别表示不删除和强制删除
⑤rgs在atl中被包含在资源文件中,然后使用DECLARE_REGISTRY_RESOURCEID,DECLARE_REGISTRY_APPID_RESOURCEID等宏来声明安装和卸载的函数,这些函数通过resouceid来读取rgs文件并进行安装卸载
⑥CRegObject类的FileRegister和FileUnregister方法可以直接对rgs文件进行注册和卸载。

HKCR 表示注册表中COM对象的注册项是HKEY_CLASS_ROOT 的缩写

NoRemove表示在反注册过程中不要删除这层注册表项;ForceRemove表示要要完全删除后面的项然后重新创建。MSDN原文如下

String Literal Description
ForceRemove Completely remove the following key (if it exists) and then recreate it.
NoRemove Do not remove the following key during Unregister.
val The following <Key Name> is actually a named value.
Delete Delete the following key during Register.
s The following value is a string.
d The following value is a DWORD.

注册后的注册表主要修改如下

1、HKEY_CLASSES_ROOT\AppID\

[HKEY_CLASSES_ROOT\AppID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}]
@="FactorySoft myShell"

2、HKEY_CLASSES_ROOT\CLSID\

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}]
@="FactorySoft myShell"

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories]

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories\{63D5F430-CFE4-11D1-B2C8-0060083BA1FB}]

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories\{63D5F432-CFE4-11D1-B2C8-0060083BA1FB}]

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\LocalServer32]
@="D:\\temp\\test\\Debug\\myShell.exe"
"ThreadingModel"="both"

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\ProgID]
@="FactorySoft.myShell.1"

[HKEY_CLASSES_ROOT\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\VersionIndependentProgID]
@="FactorySoft.myShell"

3、HKEY_CLASSES_ROOT\FactorySoft.myShell

[HKEY_CLASSES_ROOT\FactorySoft.myShell]
@="FactorySoft myShell"

[HKEY_CLASSES_ROOT\FactorySoft.myShell\CLSID]
@="{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}"

[HKEY_CLASSES_ROOT\FactorySoft.myShell\OPC]

[HKEY_CLASSES_ROOT\FactorySoft.myShell\OPC\Vendor]
@="FactorySoft, Inc"

[HKEY_CLASSES_ROOT\FactorySoft.myShell.1]
@="FactorySoft myShell"

[HKEY_CLASSES_ROOT\FactorySoft.myShell.1\CLSID]
@="{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}"

4、HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}]
@="FactorySoft myShell"

5、HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}]
@="FactorySoft myShell"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories\{63D5F430-CFE4-11D1-B2C8-0060083BA1FB}]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\Implemented Categories\{63D5F432-CFE4-11D1-B2C8-0060083BA1FB}]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\LocalServer32]
@="D:\\temp\\test\\Debug\\myShell.exe"
"ThreadingModel"="both"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\ProgID]
@="FactorySoft.myShell.1"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}\VersionIndependentProgID]
@="FactorySoft.myShell"

6、HKEY_LOCAL_MACHINE\SOFTWARE\Classes\

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell]
@="FactorySoft myShell"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell\CLSID]
@="{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell\OPC]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell\OPC\Vendor]
@="FactorySoft, Inc"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell.1]
@="FactorySoft myShell"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FactorySoft.myShell.1\CLSID]
@="{C9B70C6C-2BEE-4589-96B3-01E2F4D21C9F}"

从中可以看出s '%MODULE%'被替换成了@="D:\\temp\\test\\Debug\\myShell.exe"程序的路径

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值