我想使用WMI
中的Windows API和COM库编写一个Qt
应用程序。
我包含<qt_windows.h>
来访问窗口API
,我之前在 Visual Studio 中尝试过此操作。
但是当我包含Wbemidl.h
来声明IWbemLocator
变量时,编译器将给我以下error
:
error: Wbemidl.h: No such file or directory
这是我的code
的一部分:
HRESULT hResult = S_OK; // Result of initializing com library
BOOL bIsComLibUninit = FALSE; // A flag that determine if com library is loaded
// Initialize COM library
hResult = CoInitializeEx(0, COINIT_MULTITHREADED);
// If a previous call of CoInitializeEx occured in this thread
if(hResult == RPC_E_CHANGED_MODE)
{
OleUninitialize();
bIsComLibUninit = TRUE;
}
else if(hResult == S_OK)
{
bIsComLibUninit = TRUE;
}
// If COM library uninitialized
if(bIsComLibUninit == TRUE)
{
// Initialize COM library
hResult = CoInitializeEx(0, COINIT_MULTITHREADED);
if(hResult == S_OK)
{
// Initialize security
hResult = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, NULL);
if(hResult == S_OK)
{
IWbemLocator *pLoc = NULL;
CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
// Do stuffs
}
}
// Uninitialize COM library
CoUninitialize();
}
答案 0 :(得分:0)
错误消息告诉编译器找不到头文件。
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um
)中找到“ Wbemidl.h”,然后将PATH添加到编译器中。另外,请不要忘记.lib参考。