I have a piece of code that worked seamlessly until now. It uses the Windows Management Instrumentation API. I have not changed the code nor anything in my machine (as far as I know), but now when the code is run under the Visual Studio debugger (either 2008 or 2003), it raises an exception, apparently when calling
ConnectServer
in the code below:
HRESULT hRes;
CoInitialize(0);
IWbemLocator* pIWbemLocator= NULL;
IWbemServices* pWbemServices= NULL;
hRes= CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pIWbemLocator);
if (hRes != S_OK)
{
return false;
}
hRes= pIWbemLocator->ConnectServer(
L"ROOT\\CIMV2",
NULL,
NULL,
0,
NULL,
0,
0,
&pWbemServices
);
if (hRes != S_OK)
{
return false;
}
If I Ignore the exception, I then get a "0xC0020043: An internal error occurred in RPC." exception.
I am confident that the code is correct as it has been in use for years. And I stress that when executing without the debugger is still works (both Release and Debug builds), so I cannot blame my Windows configuration. But I am stuck when I want to debug.
Can anybody help ?