question

Codelily-7494 avatar image
0 Votes"
Codelily-7494 asked XiaopoYang-MSFT commented

why I invoke SetupDiCallClassInstaller,it returns false,and GetlastError return 13.How Can I find the reseaon ? what causes the invalid data?

SP_PROPCHANGE_PARAMS params = { sizeof(SP_CLASSINSTALL_HEADER) };
params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
params.Scope = DICS_FLAG_GLOBAL;
params.HwProfile = 0;
if (enable)
{
params.StateChange = DICS_ENABLE;
}
else
{
params.StateChange = DICS_DISABLE;
}

             if (!SetupDiSetClassInstallParams(hDevInfo, &devInfoData, (SP_CLASSINSTALL_HEADER*)&params, sizeof(SP_PROPCHANGE_PARAMS)))
             {
                 printf(" Camera: %s SetupDiSetClassInstallParams GetLastError: %d \n", currentCameraName, GetLastError());
                 return false;
             }
                
             if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &devInfoData))
             {
                 printf(" Camera: %s SetupDiCallClassInstaller GetLastError: %d \n ", currentCameraName, GetLastError());
                 return false;
             }

             SP_DEVINSTALL_PARAMS devParams;
             devParams.cbSize = sizeof(devParams);
             if (!SetupDiGetDeviceInstallParams(hDevInfo, &devInfoData, &devParams))
             {
                 //log
                 printf(" Camera: %s SetupDiGetDeviceInstallParams GetLastError: %d \n ", currentCameraName, GetLastError());
                 return false;
             }

             if (devParams.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT))
             {
                 //log
                 printf("about change Camera: %s  system need to Restart ", currentCameraName);
                 return false;
             }
             break;
windows-apic++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered XiaopoYang-MSFT commented

This test with a Network adapter works for me as Admin and in x64 =>

 WCHAR* wsAdapter = TEXT("TunnelBear Adapter V9");
 HDEVINFO hDevInfo;
 SP_DEVINFO_DATA did;
 SP_PROPCHANGE_PARAMS pcp;
 TCHAR wsBuffer[1024] = TEXT("");
 DEVPROPTYPE dpt = 0;
 BOOL bRet;
 //hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_IMAGE, 0, 0, DIGCF_PRESENT);
 //hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_BLUETOOTH, 0, 0, DIGCF_PRESENT);    
 hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, 0, 0, DIGCF_PRESENT);
 for (int i = 0; ; i++)
 {
     did.cbSize = sizeof(did);
     if (!SetupDiEnumDeviceInfo(hDevInfo, i, &did))
         break;
     bRet = SetupDiGetDeviceProperty(hDevInfo, &did, &DEVPKEY_Device_DeviceDesc, &dpt, (PBYTE)wsBuffer, 1000, NULL, 0);
     if (bRet == FALSE)
         continue;
     if (wcscmp(wsBuffer, wsAdapter) == 0)
     {
         pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
         if (SetupDiSetClassInstallParams(hDevInfo, &did, &pcp.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
         {
             pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
             pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
             pcp.HwProfile = 0;
             pcp.Scope = DICS_FLAG_GLOBAL; // DICS_FLAG_CONFIGSPECIFIC;
             pcp.StateChange = DICS_DISABLE;
             SetupDiSetClassInstallParams(hDevInfo, &did, &pcp.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS));
             TCHAR wsError[512] = TEXT("");
             if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &did) == 0)
             {        
                 DWORD dwError = GetLastError();
                 if (GetLastError() == ERROR_IN_WOW64)
                     wsprintf(wsError, TEXT("SetupDiCallClassInstaller does not work from WOW64\r\n"));
                 else
                     wsprintf(wsError, TEXT("SetupDiCallClassInstaller Error : %d\r\n"), dwError);
             }
             else
                 wsprintf(wsError, TEXT("Device state successfully changed\r\n"));
             OutputDebugString(wsError);
         }
         else
         {
             // Error...
         }
         break;
     }
 }
 SetupDiDestroyDeviceInfoList(hDevInfo);


· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thank you!
But I Don't know Why My codes run Error. It runs sucessfully in some computers (64 bit), but in some computers(64 bit) ,it runs failed.

0 Votes 0 ·

Have you set devInfoData.cbSize ? (did in my test)


0 Votes 0 ·

yes,I have set the size.like this: devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

0 Votes 0 ·
Show more comments

Is it possible to perform the same operation using other tools (Device Manager, Settings, Control Panel, etc.)?


0 Votes 0 ·