2010-08-23 56 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)的類工廠。