CoCreateInstance失败,返回错误码0x8007007e
Debug编译的COM接口好好的,但用Release编译后,用CoCreateInstance获得接口都失败。
Release编译的时候,把_ATL_STATIC_REGISTRY去掉就可以了。msdn上对_ATL_STATIC_REGISTRY的解释如下:
A symbol that indicates you want the registration code for your object to be in the object to avoid a dependency on ATL.DLL.
虽然问题解决了,但道理没想通。我同样用ATL写了个测试的COM组件,release编译选项里仍然有_ATL_STATIC_REGISTRY,测试结果是可以用的。
感觉很奇怪。希望有人能告知原因。
论坛的相关讨论:
10 楼sinall()回复于 2005-05-31 20:11:42 得分 0 搜了MSDN,找到一下:
1、
The specified module could not be found
(0x8007007e)
The specified OLE object is registered as an in-process OLE server (.DLL file), but the .DLL file could not be found or loaded.
2、
DECLARE_REGISTRY_RESOURCEID
DECLARE_REGISTRY_RESOURCEID( x )
Parameters
x
[in] Wizard-generated identifier of your resource.
Remarks
Same as DECLARE_REGISTRY_RESOURCE except that it uses a Wizard-generated UINT to identify the resource, rather than a string name.
When you create an object or control using the ATL Object Wizard, the wizard will automatically implement script-based registry support and add the DECLARE_REGISTRY_RESOURCEID macro to your files.
You can statically link with the ATL Registry Component (Registrar) for optimized registry access. To statically link to the Registrar code, add #define _ATL_STATIC_REGISTRY to your stdafx.h.
3、
Beginning with ATL 2.0, the DECLARE_STATIC_REGISTRY_RESOURCEID macro is obsolete. To statically link to the Registrar, you specify the #define _ATL_STATIC_REGISTRY statement in stdafx.h and use the DECLARE_REGISTRY_RESOURCEID macro.
4、
Add the following to end of stdafx.cpp:
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif
#include <atlimpl.cpp>
NOTE: In the release build, if you do not want to statically link in the ATL registration, then include _ATL_DLL in the preprocessor symbols in the project settings dialog box.
结论如下:
1)、检查你的stdafx.cpp看是否同上面的4
2)、问题可能出在,控件的注册能力失败。检查一下注册表,看是否有相关注册信息,注册信息是否正确。
3)、“但道理没想通。我同样用ATL写了个测试的COM组件,release编译选项里仍然有_ATL_STATIC_REGISTRY,测试结果是可以用的”,要不程序重做一遍,看是否是因为写代码的过程中人为引入的错误。
11 楼wangbab(bab)回复于 2005-06-01 09:00:06 得分 0 多谢楼上的指点。
1、stdafx.cpp和你所说的是一样的。
2、搜了一下注册表。发现注册表里只有class的CLSID,接口的IID是没有的。应该是注册出现了问题。但也是可以使用的。请问是什么原因
3、写的测试控件应该没问题。因为测试控件Debug和Release下都可以用的。而且我2个控件都是由向导升成的。
感谢sinall(一颗红星,两手准备) ( ) 找到的资料。
12 楼sinall()回复于 2005-06-01 09:05:45 得分 80我找到的资料价值不大。^_^
2、是对的。IID是不会出现在注册表中的。
有没有对比一下Debug和Release注册表有没有区别。
我觉得还是把程序简单重做一遍,看看问题是偶然的还是必然的。