Source code of Windows XP (NT5)
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.

124 lines
2.6 KiB

  1. // DrvSearchSet.cpp : Implementation of CDrvSearchSet
  2. #include "stdafx.h"
  3. #include "DevCon2.h"
  4. #include "DrvSearchSet.h"
  5. #include "Drivers.h"
  6. #include "Driver.h"
  7. #include "Device.h"
  8. #include "DevInfoSet.h"
  9. #include "DeviceConsole.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CDrvSearchSet
  12. CDrvSearchSet::~CDrvSearchSet()
  13. {
  14. if(pActualDevice) {
  15. pActualDevice->Release();
  16. }
  17. if(pTempDevice) {
  18. pTempDevice->Release();
  19. }
  20. }
  21. HRESULT CDrvSearchSet::Init(CDevice *device,DWORD searchType)
  22. {
  23. if(pActualDevice) {
  24. pActualDevice->Release();
  25. pActualDevice = NULL;
  26. }
  27. if(pTempDevice) {
  28. pTempDevice->Release();
  29. pTempDevice = NULL;
  30. }
  31. //
  32. // determine machine name that device resides on
  33. //
  34. HDEVINFO hDevInfo = device->GetDevInfoSet();
  35. if(hDevInfo == INVALID_HANDLE_VALUE) {
  36. return E_UNEXPECTED;
  37. }
  38. SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
  39. HRESULT hr;
  40. devInfoListDetail.cbSize = sizeof(devInfoListDetail);
  41. if(!SetupDiGetDeviceInfoListDetail(hDevInfo,&devInfoListDetail)) {
  42. DWORD Err = GetLastError();
  43. return HRESULT_FROM_SETUPAPI(Err);
  44. }
  45. //
  46. // create empty device info set for same machine as device
  47. //
  48. hDevInfo = SetupDiCreateDeviceInfoListEx(NULL,
  49. NULL,
  50. devInfoListDetail.RemoteMachineName[0]
  51. ? devInfoListDetail.RemoteMachineName
  52. : NULL,
  53. NULL);
  54. if(hDevInfo == INVALID_HANDLE_VALUE) {
  55. DWORD Err = GetLastError();
  56. return HRESULT_FROM_SETUPAPI(Err);
  57. }
  58. CComObject<CDevInfoSet> *pDevInfoSet = NULL;
  59. hr = CComObject<CDevInfoSet>::CreateInstance(&pDevInfoSet);
  60. if(FAILED(hr)) {
  61. return hr;
  62. }
  63. CComPtr<IDevInfoSet> pDevInfoSetPtr = pDevInfoSet;
  64. hr = pDevInfoSet->Init(hDevInfo);
  65. if(FAILED(hr)) {
  66. return hr;
  67. }
  68. //
  69. // create a single entry device in new set
  70. //
  71. CComObject<CDevice> *pDevice = NULL;
  72. hr = CComObject<CDevice>::CreateInstance(&pDevice);
  73. if(FAILED(hr)) {
  74. return hr;
  75. }
  76. CComPtr<IDevice> pDevicePtr = pDevice;
  77. //
  78. // make a note of real device
  79. //
  80. device->AddRef();
  81. pActualDevice = device;
  82. //
  83. // and make a copy of it for temp device
  84. //
  85. BSTR Instance = NULL;
  86. hr = device->get_InstanceId(&Instance);
  87. if(FAILED(hr)) {
  88. return hr;
  89. }
  90. hr = pDevice->Init(pDevInfoSet,Instance,device->DeviceConsole);
  91. SysFreeString(Instance);
  92. if(FAILED(hr)) {
  93. return hr;
  94. }
  95. pDevicePtr.Detach();
  96. pTempDevice = pDevice;
  97. SearchType = searchType;
  98. return S_OK;
  99. }
  100. HDEVINFO CDrvSearchSet::GetDevInfoSet()
  101. {
  102. if(!pTempDevice) {
  103. return INVALID_HANDLE_VALUE;
  104. }
  105. return pTempDevice->GetDevInfoSet();
  106. }
  107. PSP_DEVINFO_DATA CDrvSearchSet::GetDevInfoData()
  108. {
  109. if(!pTempDevice) {
  110. return NULL;
  111. }
  112. return &pTempDevice->DevInfoData;
  113. }