2010-08-23 55 views
1

我正在处理我的第一个COM项目,该项目将C#DLL包含C#COM Wrapper类导入到C++本机代码应用程序中。我们的应用程序基于来自微软的All-In-One Framework的CSRegFreeCOMServer VS2008示例项目。我们的系统正在使用 - VS2008,.Net3.5,boost 1.4.2和Qt 4.6.2。COM初始化错误0x80040154加载c#COM对象与c + +程序

此应用程序在我们的32位XP开发盒上运行良好。但是,当我们将系统加载到我们的Windows 7-64位系统上时。我们无法获得com对象的初始化。我们不断收到错误0x80040154(我似乎无法确定它的含义)。

我们的头文件 -

#ifndef ControlComInterface_h__ 
#define ControlComInterface_h__ 
#include <string> 
#include <ole2.h> // OLE2 Definitions 
// Importing mscorlib.tlb is necessary for .NET components 
// see: 
// http://msdn.microsoft.com/en-us/library/s5628ssw.aspx 
#import "mscorlib.tlb" raw_interfaces_only    \ 
    high_property_prefixes("_get","_put","_putref")  \ 
    rename("ReportEvent", "InteropServices_ReportEvent") 
using namespace mscorlib; 
// import the COM Declarations exported com the CSRegFreeCOMServer 
#import "..\CSRegFreeCOMServer\bin\Release\CSRegFreeCOMServer.tlb" no_namespace named_guids 
using namespace std; 
class ControlComInterface 
{ 
public: 
    ControlComInterface(void); 
    ~ControlComInterface(void); 
    IFieldsPtr spFields; 
    IPchFilePtr spPchFileWrapper; 
    bool CreateInterfaceObjects(string &errorMsg); 
}; 
#endif // ControlComInterface_h__ 

简化类代码

#include "ControlComInterface.h" 
#include <boost/lexical_cast.hpp> 
ControlComInterface::ControlComInterface(void) 
    { } 
ControlComInterface::~ControlComInterface(void) 
    { } 
bool ControlComInterface::CreateInterfaceObjects(string &errorMsg) 
{ 
HRESULT hr = S_OK; 
hr = ::CoInitialize(NULL); 
if (FAILED(hr)) 
{ 
    errorMsg = "CoInitialize failed w/err: "; 
    errorMsg.append(boost::lexical_cast<string>(hr)); 
    return false; 
    } 
errorMsg = ""; 
hr = spFields.CreateInstance(__uuidof(Fields)); 
if (FAILED(hr)) 
    { 
    errorMsg = "IFields::CreateInstance failed w/err: "; 
    errorMsg.append(boost::lexical_cast<string>(hr)); 
    return false; 
    } 
return true; 
} 

的代码与0x80040154的对呼叫的错误代码spFields.CreateInstance(...),刚刚创建的实例失败com对象中的类使用默认构造函数。

对此提出建议?

回答

1

0x80040154是REGDB_E_CLASSNOTREG。也就是说,班级没有注册。

COM无法找到(在注册表中)具有CLSID = __uuidof(Fields)的类工厂。