COM组件通过DllRegisterServer注册时候找不到CLSID

一、regsvr32的时候要以管理员的身份运行

二、我写COM组件的时候通过DllRegisterServer注册时候找不到注册成功但找不到CLSID,其实是找错地方了,我写的是一个32位的COM,在64位的电脑上注册CLSID。

long lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT,
szKeyBuf,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS , NULL,
&hKey, NULL);
这样写代码,会把CLSID注册到
计算机\HKEY_CLASSES_ROOT\WOW6432Node\CLSID{54BF6567-1007-11D1-B0AA-444553540000}里面去

三、要是想注册到64位的registry必须这样写

改成 long lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT,
szKeyBuf,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL,
&hKey, NULL);
加上 KEY_WOW64_64KEY才能在计算机\HKEY_CLASSES_ROOT\CLSID{54BF6567-1007-11D1-B0AA-444553540000}查到注册消息

KEY_WOW64_32KEY (0x0200)
Indicates that an application on 64-bit Windows should operate on the 32-bit registry view. This flag is ignored by 32-bit Windows. For more information, see Accessing an Alternate Registry View.
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values.
Windows 2000: This flag is not supported.

KEY_WOW64_64KEY (0x0100)
Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. This flag is ignored by 32-bit Windows. For more information, see Accessing an Alternate Registry View.
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values.
Windows 2000: This flag is not supported.

四、下面的函数也要作出相应的考虑,要用Ex版本上KEY_WOW64_64KEY

RegOpenKeyEx(hKeyParent, lpszKeyChild, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKeyChild);
RegDeleteKeyEx(hKeyParent, lpszKeyChild, KEY_WOW64_64KEY, 0);

五、再整理一遍写到32位registry上需要用到的函数

RegCreateKeyEx(HKEY_CLASSES_ROOT,
  szKeyBuf,
  0, NULL, REG_OPTION_NON_VOLATILE,
  KEY_ALL_ACCESS /*| KEY_WOW64_64KEY*/, NULL,
  &hKey, NULL);
RegOpenKeyEx(hKeyParent, lpszKeyChild, 0, KEY_ALL_ACCESS /*| KEY_WOW64_64KEY*/, &hKeyChild);
RegDeleteKey(hKeyParent, lpszKeyChild);

六、测试COM的程序是32位的也许他是回去32位的目录下找COM

hResult = CoCreateInstance(dictionaryCLSID, NULL,
CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);
要是没有注册到32位的registry创建对象会报错。

完整代码

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值