3

My link error:

Qt\Tools\mingw530_32\i686-w64-mingw32\include\comutil.h:278: erreur : undefined reference to `_com_util::ConvertStringToBSTR(char const*)@4'

Actually in .pro file:

LIBS += -lws2_32 -lwbemuuid -lole32

Which lib to add? lib comsuppw? Is it available for mingw?

Qt 5.10 - mingw32

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
mabro
  • 61
  • 7

2 Answers2

2

The problem was due to the function bstr_t() in:

hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process"), 
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
NULL, 
&pEnumerator);

The solution is to create BSTR strings directly:

BSTR bstr_wql = SysAllocString(L"WQL" );
BSTR bstr_sql = SysAllocString(L"SELECT * FROM Win32_Process" ); 

then use them,

hres = pSvc->ExecQuery(bstr_wql, bstr_sql, ...);

Don't forget to free the allocated memory strings after the query:

SysFreeString(bstr_wql);
SysFreeString(bstr_sql);

The linker is satisfied.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
mabro
  • 61
  • 7
-1

bstr_t(L"WQL") is work

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '22 at 03:26