为什么 CoCreateInstance 无法创建我的组件的实例?

Why CoCreateInstance can't create an instance of my component?

我正在通过 Dale Rogerson 的书 "Inside COM" 学习 COM。我尝试在注册表中注册我的组件,然后通过此信息在我的客户端代码中创建我的组件的实例。但是我看到 ::FormatMessage 函数是这样写的:Class not registered。因此,::CoCreateInstance 无法创建我的组件的实例。

我的 REG 文件:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{68584B56-9224-4DCC-AD35-1070CC9B8FDE}]
@="bush_component_01"

[HKEY_CLASSES_ROOT\CLSID\{68584B56-9224-4DCC-AD35-1070CC9B8FDE}\InprocServer32]
@="D:\projects\com_sandbox_solution_01\Debug\bush_component_01.dll"

[HKEY_CLASSES_ROOT\CLSID\{EB4BFC91-6A6E-43D1-B4CD-7A5DF24DB8D8}]
@="IID_IX"

[HKEY_CLASSES_ROOT\CLSID\{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 位注册表而言)。

不幸的是,32 位的书没有涵盖这一点。