为什么 CoCreateInstance 无法创建我的组件的实例?
Why CoCreateInstance can't create an instance of my component?
我通过Dale Rogerson的《Inside COM》这本书学习COM。我尝试在注册表中注册我的组件,然后通过此信息在我的客户端的代码中创建我的组件的实例。但是我看到::FormatMessage
函数这样写:类未注册。因此,::CoCreateInstance
不能创建我的组件的实例。
:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTCLSID{68584B56-9224-4DCC-AD35-1070CC9B8FDE}]
@="bush_component_01"
[HKEY_CLASSES_ROOTCLSID{68584B56-9224-4DCC-AD35-1070CC9B8FDE}InprocServer32]
@="D:\projects\com_sandbox_solution_01\Debug\bush_component_01.dll"
[HKEY_CLASSES_ROOTCLSID{EB4BFC91-6A6E-43D1-B4CD-7A5DF24DB8D8}]
@="IID_IX"
[HKEY_CLASSES_ROOTCLSID{EB4BFC91-6A6E-43D1-B4CD-7A5DF24DB8D8}InprocServer32]
@="D:\projects\com_sandbox_solution_01\Debug\bush_component_01.dll"
我的客户端代码:
...
// GUID of my DLL (it registered in registry (look at my REG-code above))
// {68584B56-9224-4DCC-AD35-1070CC9B8FDE}
static const CLSID CLSID_component_01 =
{ 0x68584b56, 0x9224, 0x4dcc, { 0xad, 0x35, 0x10, 0x70, 0xcc, 0x9b, 0x8f, 0xde } };
// GUID of my some interface (it registered in registry (look at my REG-code above))
// {EB4BFC91-6A6E-43D1-B4CD-7A5DF24DB8D8}
static const IID IID_IX =
{ 0xeb4bfc91, 0x6a6e, 0x43d1, { 0xb4, 0xcd, 0x7a, 0x5d, 0xf2, 0x4d, 0xb8, 0xd8 } };
...
// Code of my client:
::CoInitialize(nullptr);
IUnknown* comp = nullptr;
HRESULT hcri = ::CoCreateInstance(CLSID_component_01, nullptr,
CLSCTX_INPROC_SERVER, IID_IX, (void**)&comp);
if (FAILED(hcri)){
void* msg = nullptr;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, hcri, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&msg, 0,
nullptr);
trace("***** TRACE *****");
trace((LPTSTR)msg);
trace("****************");
keep_window_open();
return 1;
}
// But ::FormatMessage function writes this: Class not registered
为什么会发生?
在64位Windows中,32位应用程序应该使用Wow6432Node
注册子项(就64位regedit而言)。
遗憾的是,32位的书没有涵盖这些
相关文章:
- 从C++实例化QML
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何将 txt 文件中的行分隔为组件C++
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 建议在运行时将带有类实例的列表从c++导入qml
- 约束和显式模板实例化
- 通过实例理解std::move及其目的
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 如何在 QML 中实例化C++组件 - WITH 参数化构造函数
- 使用boost组件实例化C++库类的Mono C#应用程序
- NPAPI插件-传递xulrunner组件(nsCOMptr)的实例
- 为什么 CoCreateInstance 无法创建我的组件的实例?