我正在处理我的第一个COM项目,它将一个C语言的DLL导入到C++本地代码应用程序中。我们的应用程序基于Microsoft的CSRegFreeComServer VS2008示例项目
All-In-One Framework
. 我们的系统正在使用-vs2008、.net3.5、boost 1.4.2和qt 4.6.2。
此应用程序在32位xp dev设备上运行良好。但是,当我们将系统加载到Windows7-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对象中创建类的实例。
建议?