我的链接错误:
Qt \ Tools \ mingw530_32 \ i686-w64-mingw32 \ include \ comutil.h:278:erreur:对`_com_util :: ConvertStringToBSTR(char const *)@ 4'的未定义引用
实际上在.pro文件中:
LIBS += -lws2_32 -lwbemuuid -lole32
要添加哪个库? lib comsuppw?可以用于mingw吗?
Qt 5.10-mingw32
答案 0 :(得分:1)
该问题归因于以下功能:bstr_t():
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
解决方案是直接创建BSTR字符串:
BSTR bstr_wql = SysAllocString(L"WQL" );
BSTR bstr_sql = SysAllocString(L"SELECT * FROM Win32_Process" );
然后使用它们,
hres = pSvc->ExecQuery(bstr_wql, bstr_sql, ...);
不要忘记在查询后释放分配的内存字符串:
SysFreeString(bstr_wql);
SysFreeString(bstr_sql);
链接器满足。