fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <devguid.h>
  6. #include <regstr.h>
  7. #include <setupapi.h>
  8.  
  9. BOOL Test(void)
  10. {
  11. BOOL ret;
  12. DWORD dwIndex;
  13. DWORD dwSize;
  14. DWORD dwRegType;
  15. BOOL bRet;
  16. HDEVINFO hDevInfo;
  17. SP_DEVINFO_DATA sDevInfo;
  18. char strMessage[8192];
  19. char *pszName;
  20.  
  21. hDevInfo = SetupDiGetClassDevs(NULL, 0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES);
  22. if(hDevInfo == INVALID_HANDLE_VALUE) return FALSE;
  23. ret = FALSE;
  24. dwIndex = 0;
  25. ZeroMemory(&sDevInfo, sizeof(SP_DEVINFO_DATA));
  26. sDevInfo.cbSize = sizeof(SP_DEVINFO_DATA);
  27. while(1){
  28. bRet = SetupDiEnumDeviceInfo(hDevInfo, dwIndex++, &sDevInfo);
  29. if(bRet == FALSE) break;
  30. ret = FALSE;
  31. dwSize = 0;
  32. bRet = SetupDiGetDeviceRegistryPropertyA(hDevInfo, &sDevInfo, SPDRP_DEVICEDESC, &dwRegType, NULL, 0, &dwSize);
  33. pszName = (char *)malloc(dwSize);
  34. if(pszName == NULL) break;
  35. bRet = SetupDiGetDeviceRegistryPropertyA(hDevInfo, &sDevInfo, SPDRP_DEVICEDESC, &dwRegType, (BYTE*)pszName, dwSize, &dwSize);
  36. if(bRet == FALSE){ free(pszName); continue; }
  37. strcat(strMessage, pszName);
  38. free(pszName);
  39. {
  40. dwSize = 0;
  41. bRet = SetupDiGetDeviceRegistryPropertyA(hDevInfo, &sDevInfo, SPDRP_FRIENDLYNAME, &dwRegType, NULL, 0, &dwSize);
  42. pszName = (char *)malloc(dwSize);
  43. if(pszName){
  44. bRet = SetupDiGetDeviceRegistryPropertyA(hDevInfo, &sDevInfo, SPDRP_FRIENDLYNAME, &dwRegType, (BYTE*)pszName, dwSize, &dwSize);
  45. if(bRet){
  46. strcat(strMessage, " (");
  47. strcat(strMessage, pszName);
  48. strcat(strMessage, ")");
  49. }
  50. free(pszName);
  51. }
  52. }
  53. strcat(strMessage, "\n");
  54. ret = TRUE;
  55. }
  56. SetupDiDestroyDeviceInfoList(hDevInfo);
  57. MessageBoxA(NULL, strMessage, "", MB_OK); // no scroll
  58. // fprintf(stdout, strMessage);
  59. return ret;
  60. }
  61.  
  62. int main(int ac, char **av)
  63. {
  64. Test();
  65. return 0;
  66. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4:10: fatal error: windows.h: No such file or directory
 #include <windows.h>
          ^~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty