Hardware enumeration
-
This is the code from MSDN, using the api SetupDiGetClassDevEx () fuction to retrieve the list of current devices. But this program does not complies. Please debug the code so that it can enlist all the hardware devices in the computer. #include #include HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid ) /* Routine Description: Retrieves the device information set that contains that contains the devices of the specified class. Parameters: InterfaceClassGuid - The interface class GUID. Return Value: If the function succeeds, the return value is a handle to the device information set. If the function fails, the return value is zero. */ { HDEVINFO DeviceInfoSet; HDEVINFO NewDeviceInfoSet; // Create a device information set that will be the container for // the device interfaces. DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; } // Retrieve the device information set for the interface class. //int WINAPI WinMain(HINSTANCE h,HINSTANCE p,LPSTR l,int n) //{ NewDeviceInfoSet = SetupDiGetClassDevsEx( InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, DeviceInfoSet, NULL, NULL ); if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; } return NewDeviceInfoSet;
-
This is the code from MSDN, using the api SetupDiGetClassDevEx () fuction to retrieve the list of current devices. But this program does not complies. Please debug the code so that it can enlist all the hardware devices in the computer. #include #include HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid ) /* Routine Description: Retrieves the device information set that contains that contains the devices of the specified class. Parameters: InterfaceClassGuid - The interface class GUID. Return Value: If the function succeeds, the return value is a handle to the device information set. If the function fails, the return value is zero. */ { HDEVINFO DeviceInfoSet; HDEVINFO NewDeviceInfoSet; // Create a device information set that will be the container for // the device interfaces. DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; } // Retrieve the device information set for the interface class. //int WINAPI WinMain(HINSTANCE h,HINSTANCE p,LPSTR l,int n) //{ NewDeviceInfoSet = SetupDiGetClassDevsEx( InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, DeviceInfoSet, NULL, NULL ); if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; } return NewDeviceInfoSet;
it uses windows.h and stdio.h headers
-
This is the code from MSDN, using the api SetupDiGetClassDevEx () fuction to retrieve the list of current devices. But this program does not complies. Please debug the code so that it can enlist all the hardware devices in the computer. #include #include HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid ) /* Routine Description: Retrieves the device information set that contains that contains the devices of the specified class. Parameters: InterfaceClassGuid - The interface class GUID. Return Value: If the function succeeds, the return value is a handle to the device information set. If the function fails, the return value is zero. */ { HDEVINFO DeviceInfoSet; HDEVINFO NewDeviceInfoSet; // Create a device information set that will be the container for // the device interfaces. DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; } // Retrieve the device information set for the interface class. //int WINAPI WinMain(HINSTANCE h,HINSTANCE p,LPSTR l,int n) //{ NewDeviceInfoSet = SetupDiGetClassDevsEx( InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, DeviceInfoSet, NULL, NULL ); if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; } return NewDeviceInfoSet;
brilliant101 wrote: But this program does not complies. Why doesn't it? What error(s) are you receiving?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow