static private extern bool SetupDiSetClassInstallParams( IntPtr DeviceInfoSet, ref DeviceInfoData rData, ref PropChangeParams ClassInstallParams, UInt32 ClassInstallParamsSize );
static private extern bool SetupDiSetClassInstallParams(IntPtr DeviceInfoSet, ref DeviceInfoData rData, ref PropChangeParams ClassInstallParams, UInt32 ClassInstallParamsSize);
/// <summary> /// Find the related device and change the operating state. /// </summary> /// <param name="stateCode">The code for the state corresponding to /// the <i>DICS_</i> constants of Windows.</param> /// <returns></returns> private void ChangeState( int stateCode ) { // Open device var hInfoList = SetupDiGetClassDevs( ref m_Class, IntPtr.Zero, IntPtr.Zero, 2 ); // Validate if ((int) hInfoList == -1) throw new DeviceException( "Could not create Device Set" ); // With cleanup try { // Create the device information data block var pData = new DeviceInfoData(); // Initialize pData.cbSize = Marshal.SizeOf( pData ); // Find them all for (uint ix = 0; SetupDiEnumDeviceInfo( hInfoList, ix++, ref pData );) { // Load the name string name; // Check mode if (m_FilterIndex == uint.MaxValue) name = GetInstanceId( hInfoList, ref pData ); else name = ReadStringProperty( hInfoList, ref pData, (int) m_FilterIndex ); // Skip if (string.IsNullOrEmpty( name )) continue; // Compare if (!m_Adaptor.Equals( name )) continue; // Create update helper var pParams = new PropChangeParams { ClassInstallHeader = { cbSize = ClassInstallHeader.SizeOf, InstallFunction = 0x12 }, Scope = (uint) ((stateCode < 4) ? 1 : 2), StateChange = (uint) stateCode, }; // Prepare if (!SetupDiSetClassInstallParams( hInfoList, ref pData, ref pParams, PropChangeParams.SizeOf )) throw new DeviceException( "Could not update Class Install Parameters" ); // Change mode if (!SetupDiCallClassInstaller( pParams.ClassInstallHeader.InstallFunction, hInfoList, ref pData )) throw new DeviceException( "Unable to finish Change Request" ); // Did it return; } // Not found throw new DeviceException( "No Device " + m_Adaptor + " found" ); } finally { // Clean it SetupDiDestroyDeviceInfoList( hInfoList ); } }
/// <summary> /// Find the related device and change the operating state. /// </summary> /// <param name="stateCode">The code for the state corresponding to /// the <i>DICS_</i> constants of Windows.</param> /// <returns></returns> private void ChangeState(int stateCode) { // Open device var hInfoList = SetupDiGetClassDevs(ref m_Class, IntPtr.Zero, IntPtr.Zero, 2); // Validate if ((int)hInfoList == -1) { throw new DeviceException("Could not create Device Set"); } // With cleanup try { // Create the device information data block var pData = new DeviceInfoData(); // Initialize pData.cbSize = Marshal.SizeOf(pData); // Find them all for (uint ix = 0; SetupDiEnumDeviceInfo(hInfoList, ix++, ref pData);) { // Load the name string name; // Check mode if (m_FilterIndex == uint.MaxValue) { name = GetInstanceId(hInfoList, ref pData); } else { name = ReadStringProperty(hInfoList, ref pData, (int)m_FilterIndex); } // Skip if (string.IsNullOrEmpty(name)) { continue; } // Compare if (!m_Adaptor.Equals(name)) { continue; } // Create update helper var pParams = new PropChangeParams { ClassInstallHeader = { cbSize = ClassInstallHeader.SizeOf, InstallFunction = 0x12 }, Scope = (uint)((stateCode < 4) ? 1 : 2), StateChange = (uint)stateCode, }; // Prepare if (!SetupDiSetClassInstallParams(hInfoList, ref pData, ref pParams, PropChangeParams.SizeOf)) { throw new DeviceException("Could not update Class Install Parameters"); } // Change mode if (!SetupDiCallClassInstaller(pParams.ClassInstallHeader.InstallFunction, hInfoList, ref pData)) { throw new DeviceException("Unable to finish Change Request"); } // Did it return; } // Not found throw new DeviceException("No Device " + m_Adaptor + " found"); } finally { // Clean it SetupDiDestroyDeviceInfoList(hInfoList); } }