我正在查看Virtual Box的示例。我尝试快速执行以下代码,但出现了与COM相关的错误。
//#include "VirtualBox.h"
#include "rpc.h" #include
int main(int argc, char *argv[]) { HRESULT rc; // IVirtualBox *virtualBox;
do { /* 初始化COM子系统。*/ CoInitialize(NULL);
/* 实例化VirtualBox根对象。*/ // rc = CoCreateInstance(CLSID_VirtualBox, /* VirtualBox基础对象 */ // NULL, /* 不进行聚合 */ // CLSCTX_LOCAL_SERVER, /* 对象存在于此计算机上的服务器进程中 */ // IID_IVirtualBox, /* 接口的IID */ // (void**)&virtualBox);
if (!SUCCEEDED(rc)) { printf("创建VirtualBox实例时出错!rc = 0x%x\n", rc); break; }
} while (0);
//CoUninitialize(); return 0; printf("你好,世界\n");
return 0;
And the error I have got is:
<pre>
E:\vbox\mscom\samples>g++ -I E:\vbox\mscom\include -Wall helloworld.cpp -o helloworld.exe
helloworld.cpp: In function 'int main(int, char**)':
helloworld.cpp:26: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'HRESULT'
helloworld.cpp:24: warning: 'rc' is used uninitialized in this function
C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccCmOygi.o:helloworld.cpp:(.text+0x1e): undefined reference to `_imp__CoInitialize@4'
collect2: ld returned 1 exit status