Device disconnection

I have a problem with a simple function in my program, this function (listed below) should find the device with the HardwareId ID, and then turn it off / on. He finds this, but then I get an error, and GetLastError () returns a value from the range described in msdn. I noted a bug in the code with a comment. If anyone seeing this is familiar with SetupDiCallClassInstaller (), please help. I do not know where to look for this error, and if it is a code error or env system. I use Windows 7 64-bit and run this program as admin.

bool DisableInterface(bool bStatus) { IN LPTSTR HardwareId; HardwareId = L"DAUDIO\\FUNC_01&VEN_10DE&DEV_0018&SUBSYS_10DE0101"; DWORD NewState ; if(bStatus) { NewState = DICS_DISABLE; } else { NewState = DICS_ENABLE; } DWORD i, err; bool found = false; HDEVINFO hDevInfo; SP_DEVINFO_DATA spDevInfoData ; hDevInfo=SetupDiGetClassDevs(NULL, 0, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); if(hDevInfo == INVALID_HANDLE_VALUE) { printf("blad1"); return false; } spDevInfoData.cbSize=sizeof(SP_DEVINFO_DATA); for(i=0; SetupDiEnumDeviceInfo(hDevInfo, i, &spDevInfoData); i++) { DWORD DataT; LPTSTR p, buffer = NULL; DWORD buffersize = 0; // get all devices info while(!SetupDiGetDeviceRegistryProperty(hDevInfo, &spDevInfoData, SPDRP_HARDWAREID, &DataT, (PBYTE)buffer, buffersize, &buffersize) ) { if(GetLastError() == ERROR_INVALID_DATA) { break ; } else if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if(buffer) LocalFree(buffer); buffer = (wchar_t*)LocalAlloc(LPTR,buffersize); } else { goto cleanup_DeviceInfo; } } if(GetLastError() == ERROR_INVALID_DATA) continue; //find device with HardwerId for(p = buffer; *p && (p<&buffer[buffersize]) ; p += lstrlen(p) + sizeof(TCHAR)) { if( !_tcscmp(HardwareId, p) ) { found = true; break; } } if(buffer) LocalFree(buffer); // if device found change it state if(found) { SP_PROPCHANGE_PARAMS params; params.ClassInstallHeader.cbSize=sizeof(SP_CLASSINSTALL_HEADER); params.ClassInstallHeader.InstallFunction=DIF_PROPERTYCHANGE ; params.Scope=DICS_FLAG_GLOBAL ; params.StateChange = NewState ; // setup proper parameters if(!SetupDiSetClassInstallParams(hDevInfo, &spDevInfoData, &params.ClassInstallHeader, sizeof(params))) { DWORD errorcode = GetLastError(); } // use parameters if(!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &spDevInfoData)) { DWORD errorcode = GetLastError(); // error here } switch(NewState) { case DICS_DISABLE : printf("off"); break; case DICS_ENABLE : printf("on"); break; } break; } } cleanup_DeviceInfo : err = GetLastError(); SetupDiDestroyDeviceInfoList(hDevInfo); SetLastError(err); return true; } 

Thanks for the help.

+7
source share
1 answer

The error of your HEX version is 0xE0000235. In SetupAPI.h we see that this maps to ERROR_IN_WOW64.

If you look at this MSDN stream , you can see other people with this problem. About 1/3 of the way down the page, Maarten van de Bospoort MSFT responds as follows:

 The error is because you're calling SetupDiCallClassInstaller from a x86 process on a x64 machines. 

It seems that this is the cause of your problem, you are on a 64-bit version of Windows, but you are calling it from a 32-bit process. Try compiling for the 64-bit version.

+13
source

All Articles