2

我一直在我正在编写的 qt 应用程序中研究 xinput+directinput 实现。无论如何,基于一些示例代码,我有一个基本的 WBEM 设置来确定设备是否为 xinput。问题是 IWbemLocator_ConnectServer 在返回 S_OK 时没有像预期的那样填充提供的 ppNamespace。它可能与qt有关吗?有什么想法吗?

有问题的代码:

IWbemLocator *pIWbemLocator = NULL;
IEnumWbemClassObject *pEnumDevices = NULL;
IWbemClassObject *pDevices[20] = {0};
IWbemServices *pIWbemServices = NULL;
BSTR bstrNamespace = NULL;
BSTR bstrDeviceID = NULL;
BSTR bstrClassName = NULL;
DWORD uReturned = 0;
BOOL bIsXinputDevice = FALSE;
UINT iDevice = 0;
VARIANT var;
HRESULT hr;
BOOL bCleanupCOM;

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
bCleanupCOM = SUCCEEDED(hr);

// Create WMI
hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext,(LPVOID*) &pIWbemLocator);
if( FAILED(hr) || pIWbemLocator == NULL )
   goto bail;

bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto bail;
bstrClassName = SysAllocString( L"Win32_PNPEntity" );   if( bstrClassName == NULL ) goto bail;
bstrDeviceID  = SysAllocString( L"DeviceID" );          if( bstrDeviceID == NULL )  goto bail;

// Connect to WMI   
hr = IWbemLocator_ConnectServer(pIWbemLocator, bstrNamespace, NULL, NULL, NULL, 
0L, NULL, NULL, &pIWbemServices );

if( FAILED(hr) || pIWbemServices == NULL ) // This is where it fails. hr is fine, but pIWbemServices is equal to NULL
   goto bail;
4

0 回答 0