Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. For Internal use only!
  4. Module Name:
  5. INFSCAN
  6. infscan.cpp
  7. Abstract:
  8. Access to private SetupAPI functions
  9. History:
  10. Created July 2001 - JamieHun
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. SetupPrivate::SetupPrivate()
  15. {
  16. Fn_pSetupGetInfSections = NULL;
  17. Fn_SetupEnumInfSections = NULL;
  18. hSetupAPI = LoadLibrary(TEXT("setupapi.dll"));
  19. if(hSetupAPI) {
  20. Fn_SetupEnumInfSections = (Type_SetupEnumInfSections)GetProcAddress(hSetupAPI,"SetupEnumInfSectionsW");
  21. Fn_pSetupGetInfSections = (Type_pSetupGetInfSections)GetProcAddress(hSetupAPI,"pSetupGetInfSections");
  22. if(!Fn_pSetupGetInfSections) {
  23. Fn_pSetupGetInfSections = (Type_pSetupGetInfSections)GetProcAddress(hSetupAPI,"SetupGetInfSections");
  24. }
  25. }
  26. }
  27. SetupPrivate::~SetupPrivate()
  28. {
  29. if(hSetupAPI) {
  30. FreeLibrary(hSetupAPI);
  31. }
  32. }
  33. bool SetupPrivate::GetInfSections(HINF hInf,StringList & sections)
  34. {
  35. if(Fn_SetupEnumInfSections) {
  36. return GetInfSectionsNewWay(hInf,sections);
  37. }
  38. if(Fn_pSetupGetInfSections) {
  39. return GetInfSectionsOldWay(hInf,sections);
  40. }
  41. return false;
  42. }
  43. bool SetupPrivate::GetInfSectionsOldWay(HINF hInf,StringList & sections)
  44. {
  45. UINT Size;
  46. UINT SizeNeeded;
  47. if(Fn_pSetupGetInfSections(hInf,NULL,0,&SizeNeeded) || GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
  48. SizeNeeded+=2;
  49. PWSTR text = new WCHAR[SizeNeeded];
  50. if(!text) {
  51. return false;
  52. }
  53. if(!Fn_pSetupGetInfSections(hInf,text,SizeNeeded,NULL)) {
  54. delete [] text;
  55. return false;
  56. }
  57. PWSTR str = text;
  58. sections.clear();
  59. while(*str) {
  60. _wcslwr(str);
  61. sections.push_back(ConvertString(str));
  62. str+=wcslen(str)+1;
  63. }
  64. delete [] text;
  65. return true;
  66. }
  67. return false;
  68. }
  69. bool SetupPrivate::GetInfSectionsNewWay(HINF hInf,StringList & sections)
  70. {
  71. WCHAR buf[256];
  72. int inc;
  73. for(inc = 0; Fn_SetupEnumInfSections(hInf,inc,buf,ASIZE(buf),NULL); inc++) {
  74. _wcslwr(buf);
  75. sections.push_back(ConvertString(buf));
  76. }
  77. return inc ? true : false;
  78. }