VirtualBox 创建com对象失败,解决方法

解决办法:


右键VirtualBox的桌面快捷方式,选择属性,选到兼容性选项卡,勾选“以兼容模式运行这个程序”,下拉框选择Windows Server 2008 (Service Pack 1),再勾选“以管理员身份运行此程序”,确定。重新打开,发现OK了

展开阅读全文

创建COM对象失败????

11-22

我在网上下载了《COM技术内幕》的电子书及源代码,但是源代码却运行失败,在调用 HRESULT hr = ::CoCreateInstancernrn(CLSID_Component1,NULL,CLSCTX_INPROC_SERVER,IID_IX,(void**)&pIX) ;直接不成功。我把源代码贴出来:rnrn[code=C/C++]#include rn#include rnrn#include "Iface.h"rnrnvoid trace(const char* msg) cout << "Client: \t\t" << msg << endl ;rnrn//rn// main functionrn//rnint main()rnrn // Initialize COM Libraryrn CoInitialize(NULL) ;rnrn trace("Call CoCreateInstance to create") ;rn trace(" component and get interface IX.") ;rn IX* pIX = NULL ; rn HRESULT hr = ::CoCreateInstance(CLSID_Component1,rn NULL, rn CLSCTX_INPROC_SERVER,rn IID_IX, rn (void**)&pIX) ;rn if (SUCCEEDED(hr))rn rn trace("Succeeded getting IX.") ;rn pIX->Fx() ; // Use interface IX.rnrn trace("Ask for interface IY.") ;rn IY* pIY = NULL ;rn hr = pIX->QueryInterface(IID_IY, (void**)&pIY) ;rn if (SUCCEEDED(hr))rn rn trace("Succeeded getting IY.") ;rn pIY->Fy() ; // Use interface IY.rn pIY->Release() ;rn trace("Release IY interface.") ;rn rn elsern rn trace("Could not get interface IY.") ;rn rnrn trace("Ask for interface IZ.") ;rnrn IZ* pIZ = NULL ;rn hr = pIX->QueryInterface(IID_IZ, (void**)&pIZ) ;rn if (SUCCEEDED(hr))rn rn trace("Succeeded in getting interface IZ.") ;rn pIZ->Fz() ;rn pIZ->Release() ;rn trace("Release IZ interface.") ;rn rn elsern rn trace("Could not get interface IZ.") ;rn rnrn trace("Release IX interface.") ;rn pIX->Release() ;rn rn elsern rn cout << "Client: \t\tCould not create component. hr = "rn << hex << hr << endl ; rn rnrn // Uninitialize COM Libraryrn CoUninitialize() ;rnrn return 0 ;rn[/code]rnrnIFace.h是接口的头文件,没有什么东西,每次在运行的时候,CoCreateInstance返回失败,这个是为什么呢???书上似乎说运行这个函数的时候回去注册表中搜索DLL,当然DLL文件没有贴出来了 论坛

没有更多推荐了,返回首页