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.

794 lines
27 KiB

  1. //=================================================================
  2. //
  3. // Configmgrapi.cpp
  4. //
  5. // Copyright (c) 1999-2002 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <cominit.h>
  10. #include "DllWrapperBase.h"
  11. #ifdef WIN9XONLY
  12. #include "Cim32NetApi.h"
  13. #endif
  14. #include "configmgrapi.h"
  15. //
  16. // resource management failures
  17. //
  18. extern BOOL bAddInstanceCreatorFailure ;
  19. /**********************************************************************************************************
  20. * Register this class with the CResourceManager.
  21. **********************************************************************************************************/
  22. // {4D060F17-C791-11d2-B353-00105A1F8569}
  23. static const GUID guidCFGMGRAPI =
  24. { 0x4d060f17, 0xc791, 0x11d2, { 0xb3, 0x53, 0x0, 0x10, 0x5a, 0x1f, 0x85, 0x69 } };
  25. class CConfigMgrApiCreatorRegistration
  26. {
  27. public:
  28. CConfigMgrApiCreatorRegistration ()
  29. {
  30. try
  31. {
  32. BOOL bNonFailure =
  33. CResourceManager::sm_TheResourceManager.AddInstanceCreator ( guidCFGMGRAPI, CConfigMgrApiCreator ) ;
  34. if ( FALSE == bNonFailure )
  35. {
  36. bAddInstanceCreatorFailure = TRUE ;
  37. }
  38. }
  39. catch ( CHeap_Exception& e_HE )
  40. {
  41. bAddInstanceCreatorFailure = TRUE ;
  42. }
  43. }
  44. ~CConfigMgrApiCreatorRegistration ()
  45. {}
  46. static CResource * CConfigMgrApiCreator ( PVOID pData )
  47. {
  48. CConfigMgrAPI *t_pConfigmgrapi = new CConfigMgrAPI ;
  49. if ( !t_pConfigmgrapi )
  50. {
  51. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  52. }
  53. return t_pConfigmgrapi ;
  54. }
  55. };
  56. CConfigMgrApiCreatorRegistration MyCConfigMgrApiCreatorRegistration ;
  57. /**********************************************************************************************************/
  58. // String array for converting between 32-bit ULONG Constants and
  59. // corresponding registry strings in 16-bit land
  60. const char* CConfigMgrAPI::s_pszRegistryStrings[] = {
  61. CM_DRP_DEVICEDESC_S,
  62. CM_DRP_HARDWAREID_S,
  63. CM_DRP_COMPATIBLEIDS_S,
  64. CM_DRP_NTDEVICEPATHS_S,
  65. CM_DRP_SERVICE_S,
  66. CM_DRP_CONFIGURATION_S,
  67. CM_DRP_CONFIGURATIONVECTOR_S,
  68. CM_DRP_CLASS_S,
  69. CM_DRP_CLASSGUID_S,
  70. CM_DRP_DRIVER_S,
  71. CM_DRP_CONFIGFLAGS_S,
  72. CM_DRP_MFG_S,
  73. CM_DRP_FRIENDLYNAME_S,
  74. CM_DRP_LOCATION_INFORMATION_S,
  75. CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME_S,
  76. CM_DRP_CAPABILITIES_S,
  77. CM_DRP_UI_NUMBER_S,
  78. CM_DRP_UPPERFILTERS_S,
  79. CM_DRP_LOWERFILTERS_S,
  80. CM_DRP_BUSTYPEGUID_S,
  81. CM_DRP_LEGACYBUSTYPE_S,
  82. CM_DRP_BUSNUMBER_S,
  83. CM_DRP_ENUMERATOR_NAME_S,
  84. CM_DRP_MAX_S
  85. };
  86. ULONG CConfigMgrAPI::s_pszRegistryValueTypes[] = {
  87. REG_SZ, // CM_DRP_DEVICEDESC_S
  88. REG_SZ, // CM_DRP_HARDWAREID_S
  89. REG_SZ, // CM_DRP_COMPATIBLEIDS_S
  90. REG_SZ, // CM_DRP_NTDEVICEPATHS_S
  91. REG_SZ, // CM_DRP_SERVICE_S
  92. REG_SZ, // CM_DRP_CONFIGURATION_S
  93. REG_SZ, // CM_DRP_CONFIGURATIONVECTOR_S
  94. REG_SZ, // CM_DRP_CLASS_S
  95. REG_SZ, // CM_DRP_CLASSGUID_S
  96. REG_SZ, // CM_DRP_DRIVER_S
  97. REG_BINARY, // CM_DRP_CONFIGFLAGS_S
  98. REG_SZ, // CM_DRP_MFG_S
  99. REG_SZ, // CM_DRP_FRIENDLYNAME_S
  100. REG_SZ, // CM_DRP_LOCATION_INFORMATION_S
  101. REG_BINARY, // CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME_S
  102. REG_BINARY, // CM_DRP_CAPABILITIES_S
  103. REG_SZ, // CM_DRP_UI_NUMBER_S
  104. REG_SZ, // CM_DRP_UPPERFILTERS_S
  105. REG_SZ, // CM_DRP_LOWERFILTERS_S
  106. REG_SZ, // CM_DRP_BUSTYPEGUID_S
  107. REG_BINARY, // CM_DRP_LEGACYBUSTYPE_S
  108. REG_BINARY, // CM_DRP_BUSNUMBER_S
  109. REG_SZ, // CM_DRP_ENUMERATOR_NAME_S
  110. REG_SZ // CM_DRP_MAX_S
  111. };
  112. CConfigMgrAPI::CConfigMgrAPI( void )
  113. :
  114. #ifdef NTONLY
  115. m_hConfigMgrDll( NULL ),
  116. m_pCM_Connect_MachineA( NULL ),
  117. m_pCM_Disconnect_Machine( NULL ),
  118. m_pCM_Locate_DevNode( NULL ),
  119. m_pCM_Get_Child( NULL ),
  120. m_pCM_Get_Sibling( NULL ),
  121. m_pCM_Get_DevNode_Registry_Property( NULL ),
  122. m_pCM_Get_DevNode_Status( NULL ),
  123. m_pCM_Get_First_Log_Config( NULL ),
  124. m_pCM_Get_Next_Res_Des( NULL ),
  125. m_pCM_Get_Res_Des_Data( NULL ),
  126. m_pCM_Get_Res_Des_Data_Size( NULL ),
  127. m_pCM_Free_Log_Conf_Handle( NULL ),
  128. m_pCM_Free_Res_Des_Handle( NULL ),
  129. m_pCM_Get_Device_IDA( NULL ),
  130. m_pCM_Get_Device_ID_Size( NULL ),
  131. m_pCM_Get_Parent( NULL )
  132. #endif
  133. #ifdef WIN9XONLY
  134. m_pCim32NetApi(NULL)
  135. /*
  136. m_pCM16_Locate_DevNode( NULL ),
  137. m_pCM16_Get_Child( NULL ),
  138. m_pCM16_Get_Sibling( NULL ),
  139. m_pCM16_Read_Registry_Value( NULL ),
  140. m_pCM16_Get_DevNode_Status( NULL ),
  141. m_pCM16_Get_Device_ID( NULL ),
  142. m_pCM16_Get_Device_ID_Size( NULL ),
  143. m_pCM16_Get_First_Log_Conf( NULL ),
  144. m_pCM16_Get_Next_Res_Des( NULL ),
  145. m_pCM16_Get_Res_Des_Data_Size( NULL ),
  146. m_pCM16_Get_Res_Des_Data( NULL ),
  147. m_pCM16_Get_Bus_Info( NULL ),
  148. m_pCM16_Get_Parent( NULL ),
  149. */
  150. #endif
  151. {
  152. #ifdef NTONLY
  153. {
  154. m_hConfigMgrDll = LoadLibrary(_T("CFGMGR32.DLL"));
  155. if ( NULL == m_hConfigMgrDll )
  156. {
  157. try
  158. {
  159. WCHAR szConfigMgrDllPathStack [ MAX_PATH ] ;
  160. DWORD t_charSize = GetWindowsDirectory ( szConfigMgrDllPathStack , sizeof ( szConfigMgrDllPathStack ) / sizeof ( WCHAR ) ) ;
  161. BOOL t_HeapAllocatedPath = FALSE ;
  162. BOOL t_HeapAllocatedPathCat = FALSE ;
  163. WCHAR *szConfigMgrDllPath = szConfigMgrDllPathStack ;
  164. if ( 0 != t_charSize )
  165. {
  166. if ( t_charSize > MAX_PATH )
  167. {
  168. t_HeapAllocatedPath = TRUE ;
  169. }
  170. }
  171. if ( t_HeapAllocatedPath )
  172. {
  173. szConfigMgrDllPath = ( WCHAR * ) new WCHAR [ t_charSize + 1 + ( sizeof ( L"\\system32\\CFGMGR32.DLL" ) / sizeof ( WCHAR ) ) ];
  174. if ( ! szConfigMgrDllPath )
  175. {
  176. ::SetLastError ( ERROR_NOT_ENOUGH_MEMORY ) ;
  177. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  178. }
  179. }
  180. //
  181. // scope guard
  182. //
  183. // this will create scope variable that makes sure
  184. // de-allocation is performed based on BOOLEAN
  185. //
  186. ON_BLOCK_EXIT_IF ( t_HeapAllocatedPath, deleteArray < WCHAR >, szConfigMgrDllPath ) ;
  187. if ( t_HeapAllocatedPath )
  188. {
  189. //
  190. // we need to get folder again
  191. //
  192. t_charSize = GetWindowsDirectory ( szConfigMgrDllPath , t_charSize + 1 ) ;
  193. }
  194. if ( 0 != t_charSize )
  195. {
  196. WCHAR * szConfigMgrDllPathOld = szConfigMgrDllPath ;
  197. if ( FALSE == t_HeapAllocatedPath )
  198. {
  199. if ( ( t_charSize + 1 + ( sizeof ( L"\\system32\\CFGMGR32.DLL" ) / sizeof ( WCHAR ) ) ) > MAX_PATH )
  200. {
  201. t_HeapAllocatedPathCat = TRUE ;
  202. }
  203. if ( t_HeapAllocatedPathCat )
  204. {
  205. szConfigMgrDllPath = ( WCHAR * ) new WCHAR [ t_charSize + 1 + ( sizeof ( L"\\system32\\CFGMGR32.DLL" ) / sizeof ( WCHAR ) ) ];
  206. if ( ! szConfigMgrDllPath )
  207. {
  208. ::SetLastError ( ERROR_NOT_ENOUGH_MEMORY ) ;
  209. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  210. }
  211. }
  212. }
  213. //
  214. // scope guard
  215. //
  216. // this will create scope variable that makes sure
  217. // de-allocation is performed based on BOOLEAN
  218. //
  219. ON_BLOCK_EXIT_IF ( t_HeapAllocatedPathCat, deleteArray < WCHAR >, szConfigMgrDllPath ) ;
  220. if ( t_HeapAllocatedPathCat )
  221. {
  222. StringCchCopyW( szConfigMgrDllPath, t_charSize + 1 , szConfigMgrDllPathOld );
  223. }
  224. StringCchCatW( szConfigMgrDllPath, t_charSize + 1 + ( sizeof ( L"\\system32\\CFGMGR32.DLL" ) / sizeof ( WCHAR ) ), L"\\system32\\CFGMGR32.DLL" );
  225. m_hConfigMgrDll = LoadLibrary(szConfigMgrDllPath);
  226. }
  227. }
  228. catch ( ... )
  229. {
  230. m_hConfigMgrDll = NULL;
  231. }
  232. }
  233. if ( NULL != m_hConfigMgrDll )
  234. {
  235. m_pCM_Connect_MachineA = (PCFGMGR32_CM_CONNECT_MACHINEA) GetProcAddress( m_hConfigMgrDll, "CM_Connect_MachineA" );
  236. m_pCM_Disconnect_Machine = (PCFGMGR32_CM_DISCONNECT_MACHINE) GetProcAddress( m_hConfigMgrDll, "CM_Disconnect_Machine" );
  237. #ifdef UNICODE
  238. m_pCM_Locate_DevNode = (PCFGMGR32_CM_LOCATE_DEVNODE) GetProcAddress( m_hConfigMgrDll, "CM_Locate_DevNodeW" );
  239. m_pCM_Get_DevNode_Registry_Property = (PCFGMGR32_CM_GET_DEVNODE_REGISTRY_PROPERTY) GetProcAddress( m_hConfigMgrDll, "CM_Get_DevNode_Registry_PropertyW" );
  240. #else
  241. m_pCM_Get_DevNode_Registry_Property = (PCFGMGR32_CM_GET_DEVNODE_REGISTRY_PROPERTY) GetProcAddress( m_hConfigMgrDll, "CM_Get_DevNode_Registry_PropertyA" );
  242. m_pCM_Locate_DevNode = (PCFGMGR32_CM_LOCATE_DEVNODE) GetProcAddress( m_hConfigMgrDll, "CM_Locate_DevNodeA" );
  243. #endif
  244. m_pCM_Get_Child = (PCFGMGR32_CM_GET_CHILD) GetProcAddress( m_hConfigMgrDll, "CM_Get_Child" );
  245. m_pCM_Get_Sibling = (PCFGMGR32_CM_GET_SIBLING) GetProcAddress( m_hConfigMgrDll, "CM_Get_Sibling" );
  246. m_pCM_Get_DevNode_Status = (PCFGMGR32_CM_GET_DEVNODE_STATUS) GetProcAddress( m_hConfigMgrDll, "CM_Get_DevNode_Status" );
  247. m_pCM_Get_First_Log_Config = (PCFGMGR32_CM_GET_FIRST_LOG_CONF) GetProcAddress( m_hConfigMgrDll, "CM_Get_First_Log_Conf" );
  248. m_pCM_Get_Next_Res_Des = (PCFGMGR32_CM_GET_NEXT_RES_DES) GetProcAddress( m_hConfigMgrDll, "CM_Get_Next_Res_Des" );
  249. m_pCM_Get_Res_Des_Data = (PCFGMGR32_CM_GET_RES_DES_DATA) GetProcAddress( m_hConfigMgrDll, "CM_Get_Res_Des_Data" );
  250. m_pCM_Get_Res_Des_Data_Size = (PCFGMGR32_CM_GET_RES_DES_DATA_SIZE) GetProcAddress( m_hConfigMgrDll, "CM_Get_Res_Des_Data_Size" );
  251. m_pCM_Free_Log_Conf_Handle = (PCFGMGR32_CM_FREE_LOG_CONF_HANDLE) GetProcAddress( m_hConfigMgrDll, "CM_Free_Log_Conf_Handle" );
  252. m_pCM_Free_Res_Des_Handle = (PCFGMGR32_CM_FREE_RES_DES_HANDLE) GetProcAddress( m_hConfigMgrDll, "CM_Free_Res_Des_Handle" );
  253. m_pCM_Get_Device_IDA = (PCFGMGR32_CM_GET_DEVICE_IDA) GetProcAddress( m_hConfigMgrDll, "CM_Get_Device_IDA" );
  254. m_pCM_Get_Device_ID_Size = (PCFGMGR32_CM_GET_DEVICE_ID_SIZE) GetProcAddress( m_hConfigMgrDll, "CM_Get_Device_ID_Size" );
  255. m_pCM_Get_Parent = (PCFGMGR32_CM_GET_PARENT) GetProcAddress( m_hConfigMgrDll, "CM_Get_Parent" );
  256. }
  257. else
  258. {
  259. // this is possible to be neccessary in the future !!!
  260. // resource manager may start to care about error from load library
  261. //
  262. // let resource manager know load failed
  263. //
  264. m_bValid = FALSE;
  265. m_dwCreationError = ::GetLastError ();
  266. LogErrorMessage(L"Failed to load library cfgmgr32.dll");
  267. }
  268. }
  269. #endif
  270. #ifdef WIN9XONLY
  271. {
  272. m_pCim32NetApi = HoldSingleCim32NetPtr::GetCim32NetApiPtr();
  273. /*
  274. if ( NULL != m_hConfigMgrDll )
  275. {
  276. m_pCM16_Locate_DevNode = (PCIM32THK_CM_LOCATE_DEVNODE) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Locate_DevNode" );
  277. m_pCM16_Get_Child = (PCIM32THK_CM_GET_CHILD) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Child" );
  278. m_pCM16_Get_Sibling = (PCIM32THK_CM_GET_SIBLING) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Sibling" );
  279. m_pCM16_Read_Registry_Value = (PCIM32THK_CM_READ_REGISTRY_VALUE) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Read_Registry_Value" );
  280. m_pCM16_Get_DevNode_Status = (PCIM32THK_CM_GET_DEVNODE_STATUS) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_DevNode_Status" );
  281. m_pCM16_Get_Device_ID = (PCIM32THK_CM_GET_DEVICE_ID) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Device_ID" );
  282. m_pCM16_Get_Device_ID_Size = (PCIM32THK_CM_GET_DEVICE_ID_SIZE) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Device_ID_Size" );
  283. m_pCM16_Get_First_Log_Conf = (PCIM32THK_CM_GET_FIRST_LOG_CONF) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_First_Log_Conf" );
  284. m_pCM16_Get_Next_Res_Des = (PCIM32THK_CM_GET_NEXT_RES_DES) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Next_Res_Des" );
  285. m_pCM16_Get_Res_Des_Data_Size = (PCIM32THK_CM_GET_RES_DES_DATA_SIZE) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Res_Des_Data_Size" );
  286. m_pCM16_Get_Res_Des_Data = (PCIM32THK_CM_GET_RES_DES_DATA) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Res_Des_Data" );
  287. m_pCM16_Get_Bus_Info = (PCIM32THK_CM_GET_BUS_INFO) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Bus_Info" );
  288. m_pCM16_Get_Parent = (PCIM32THK_CM_GET_PARENT) GetProcAddress( m_hConfigMgrDll, "CIM32THK_CM_Get_Parent" );
  289. }
  290. */
  291. }
  292. #endif
  293. }
  294. CConfigMgrAPI::~CConfigMgrAPI( void )
  295. {
  296. #ifdef NTONLY
  297. if ( NULL != m_hConfigMgrDll )
  298. {
  299. FreeLibrary( m_hConfigMgrDll );
  300. }
  301. #endif
  302. #ifdef WIN9XONLY
  303. if(m_pCim32NetApi != NULL)
  304. {
  305. CResourceManager::sm_TheResourceManager.ReleaseResource(g_guidCim32NetApi, m_pCim32NetApi);
  306. m_pCim32NetApi = NULL;
  307. }
  308. #endif
  309. }
  310. CONFIGRET CConfigMgrAPI::CM_Connect_MachineA( PCSTR UNCServerName, PHMACHINE phMachine )
  311. {
  312. CONFIGRET cr = CR_INVALID_POINTER;
  313. #ifdef NTONLY
  314. if ( NULL != m_pCM_Connect_MachineA )
  315. {
  316. cr = m_pCM_Connect_MachineA( UNCServerName, phMachine );
  317. }
  318. #endif
  319. return cr;
  320. }
  321. CONFIGRET CConfigMgrAPI::CM_Disconnect_Machine( HMACHINE hMachine )
  322. {
  323. CONFIGRET cr = CR_INVALID_POINTER;
  324. #ifdef NTONLY
  325. if ( NULL != m_pCM_Connect_MachineA )
  326. {
  327. cr = m_pCM_Disconnect_Machine( hMachine );
  328. }
  329. #endif
  330. return cr;
  331. }
  332. CONFIGRET CConfigMgrAPI::CM_Get_Parent( PDEVINST pdnDevInst, DEVINST DevInst, ULONG ulFlags )
  333. {
  334. CONFIGRET cr = CR_INVALID_POINTER;
  335. #ifdef NTONLY
  336. {
  337. if ( NULL != m_pCM_Get_Parent )
  338. {
  339. cr = m_pCM_Get_Parent( pdnDevInst, DevInst, ulFlags );
  340. }
  341. }
  342. #endif
  343. #ifdef WIN9XONLY
  344. {
  345. if ( NULL != m_pCim32NetApi )
  346. {
  347. cr = m_pCim32NetApi->CIM32THK_CM_Get_Parent( pdnDevInst, DevInst, ulFlags );
  348. }
  349. }
  350. #endif
  351. return cr;
  352. }
  353. CONFIGRET CConfigMgrAPI::CM_Get_Child( PDEVINST pdnDevInst, DEVINST DevInst, ULONG ulFlags )
  354. {
  355. CONFIGRET cr = CR_INVALID_POINTER;
  356. #ifdef NTONLY
  357. {
  358. if ( NULL != m_pCM_Get_Child )
  359. {
  360. cr = m_pCM_Get_Child( pdnDevInst, DevInst, ulFlags );
  361. }
  362. }
  363. #endif
  364. #ifdef WIN9XONLY
  365. {
  366. if ( NULL != m_pCim32NetApi )
  367. {
  368. cr = m_pCim32NetApi->CIM32THK_CM_Get_Child( pdnDevInst, DevInst, ulFlags );
  369. }
  370. }
  371. #endif
  372. return cr;
  373. }
  374. CONFIGRET CConfigMgrAPI::CM_Get_Sibling( PDEVINST pdnDevInst, DEVINST DevInst, ULONG ulFlags )
  375. {
  376. CONFIGRET cr = CR_INVALID_POINTER;
  377. #ifdef NTONLY
  378. {
  379. if ( NULL != m_pCM_Get_Sibling )
  380. {
  381. cr = m_pCM_Get_Sibling( pdnDevInst, DevInst, ulFlags );
  382. }
  383. }
  384. #endif
  385. #ifdef WIN9XONLY
  386. {
  387. if ( NULL != m_pCim32NetApi )
  388. {
  389. cr = m_pCim32NetApi->CIM32THK_CM_Get_Sibling( pdnDevInst, DevInst, ulFlags );
  390. }
  391. }
  392. #endif
  393. return cr;
  394. }
  395. CONFIGRET CConfigMgrAPI::CM_Locate_DevNode( PDEVINST pdnDevInst, TCHAR *pDeviceID, ULONG ulFlags )
  396. {
  397. CONFIGRET cr = CR_INVALID_POINTER;
  398. #ifdef NTONLY
  399. {
  400. if ( NULL != m_pCM_Locate_DevNode )
  401. {
  402. cr = m_pCM_Locate_DevNode( pdnDevInst, pDeviceID, ulFlags );
  403. }
  404. }
  405. #endif
  406. #ifdef WIN9XONLY
  407. {
  408. if ( NULL != m_pCim32NetApi )
  409. {
  410. #ifndef UNICODE
  411. cr = m_pCim32NetApi->CIM32THK_CM_Locate_DevNode( pdnDevInst, pDeviceID, ulFlags );
  412. #endif
  413. }
  414. }
  415. #endif
  416. return cr;
  417. }
  418. CONFIGRET CConfigMgrAPI::CM_Get_DevNode_Registry_PropertyA( DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
  419. PVOID Buffer, PULONG pulLength, ULONG ulFlags )
  420. {
  421. CONFIGRET cr = CR_INVALID_POINTER;
  422. #ifdef NTONLY
  423. {
  424. if ( NULL != m_pCM_Get_DevNode_Registry_Property )
  425. {
  426. cr = m_pCM_Get_DevNode_Registry_Property( dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags );
  427. }
  428. }
  429. #endif
  430. #ifdef WIN9XONLY
  431. {
  432. if ( NULL != m_pCim32NetApi
  433. && CM_DRP_MIN <= ulProperty
  434. && CM_DRP_MAX > ulProperty )
  435. {
  436. cr = m_pCim32NetApi->CIM32THK_CM_Read_Registry_Value( dnDevInst, NULL, s_pszRegistryStrings[ulProperty-1], s_pszRegistryValueTypes[ulProperty-1], Buffer, pulLength, 0 );
  437. // Fake the returned type since we at least had a match
  438. *pulRegDataType = s_pszRegistryValueTypes[ulProperty-1];
  439. }
  440. }
  441. #endif
  442. return cr;
  443. }
  444. CONFIGRET CConfigMgrAPI::CM_Get_DevNode_Status( PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst, ULONG ulFlags )
  445. {
  446. CONFIGRET cr = CR_INVALID_POINTER;
  447. #ifdef NTONLY
  448. {
  449. if ( NULL != m_pCM_Get_DevNode_Status )
  450. {
  451. cr = m_pCM_Get_DevNode_Status( pulStatus, pulProblemNumber, dnDevInst, ulFlags );
  452. }
  453. }
  454. #endif
  455. #ifdef WIN9XONLY
  456. {
  457. if ( NULL != m_pCim32NetApi )
  458. {
  459. cr = m_pCim32NetApi->CIM32THK_CM_Get_DevNode_Status( pulStatus, pulProblemNumber, dnDevInst, ulFlags );
  460. }
  461. }
  462. #endif
  463. return cr;
  464. }
  465. CONFIGRET CConfigMgrAPI::CM_Get_First_Log_Conf( PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags )
  466. {
  467. CONFIGRET cr = CR_INVALID_POINTER;
  468. #ifdef NTONLY
  469. {
  470. if ( NULL != m_pCM_Get_First_Log_Config )
  471. {
  472. cr = m_pCM_Get_First_Log_Config( plcLogConf, dnDevInst, ulFlags );
  473. }
  474. }
  475. #endif
  476. #ifdef WIN9XONLY
  477. {
  478. if ( NULL != m_pCim32NetApi )
  479. {
  480. cr = m_pCim32NetApi->CIM32THK_CM_Get_First_Log_Conf( plcLogConf, dnDevInst, ulFlags );
  481. }
  482. }
  483. #endif
  484. return cr;
  485. }
  486. CONFIGRET CConfigMgrAPI::CM_Get_Next_Res_Des( PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource, PRESOURCEID pResourceID, ULONG ulFlags )
  487. {
  488. CONFIGRET cr = CR_INVALID_POINTER;
  489. #ifdef NTONLY
  490. {
  491. if ( NULL != m_pCM_Get_Next_Res_Des )
  492. {
  493. cr = m_pCM_Get_Next_Res_Des( prdResDes, rdResDes, ForResource, pResourceID, ulFlags );
  494. }
  495. }
  496. #endif
  497. #ifdef WIN9XONLY
  498. {
  499. if ( NULL != m_pCim32NetApi )
  500. {
  501. cr = m_pCim32NetApi->CIM32THK_CM_Get_Next_Res_Des( prdResDes, rdResDes, ForResource, pResourceID, ulFlags );
  502. }
  503. }
  504. #endif
  505. return cr;
  506. }
  507. CONFIGRET CConfigMgrAPI::CM_Get_Res_Des_Data( RES_DES rdResDes, PVOID Buffer, ULONG BufferLen, ULONG ulFlags )
  508. {
  509. CONFIGRET cr = CR_INVALID_POINTER;
  510. #ifdef NTONLY
  511. {
  512. if ( NULL != m_pCM_Get_Res_Des_Data )
  513. {
  514. cr = m_pCM_Get_Res_Des_Data( rdResDes, Buffer, BufferLen, ulFlags );
  515. }
  516. }
  517. #endif
  518. #ifdef WIN9XONLY
  519. {
  520. if ( NULL != m_pCim32NetApi )
  521. {
  522. cr =m_pCim32NetApi-> CIM32THK_CM_Get_Res_Des_Data( rdResDes, Buffer, BufferLen, ulFlags );
  523. }
  524. }
  525. #endif
  526. return cr;
  527. }
  528. CONFIGRET CConfigMgrAPI::CM_Get_Res_Des_Data_Size( PULONG pulSize, RES_DES rdResDes, ULONG ulFlags )
  529. {
  530. CONFIGRET cr = CR_INVALID_POINTER;
  531. #ifdef NTONLY
  532. {
  533. if ( NULL != m_pCM_Get_Res_Des_Data_Size )
  534. {
  535. cr = m_pCM_Get_Res_Des_Data_Size( pulSize, rdResDes, ulFlags );
  536. }
  537. }
  538. #endif
  539. #ifdef WIN9XONLY
  540. {
  541. if ( NULL != m_pCim32NetApi )
  542. {
  543. cr = m_pCim32NetApi->CIM32THK_CM_Get_Res_Des_Data_Size( pulSize, rdResDes, ulFlags );
  544. }
  545. }
  546. #endif
  547. return cr;
  548. }
  549. CONFIGRET CConfigMgrAPI::CM_Free_Log_Conf_Handle( LOG_CONF lcLogConf )
  550. {
  551. CONFIGRET cr = CR_INVALID_POINTER;
  552. // This function does NOT appear to have a 16-bit implementation or an
  553. // equivalent thereof.
  554. #ifdef NTONLY
  555. {
  556. if ( NULL != m_pCM_Free_Log_Conf_Handle )
  557. {
  558. cr = m_pCM_Free_Log_Conf_Handle( lcLogConf );
  559. }
  560. }
  561. #endif
  562. return cr;
  563. }
  564. CONFIGRET CConfigMgrAPI::CM_Free_Res_Des_Handle( RES_DES rdResDes )
  565. {
  566. CONFIGRET cr = CR_INVALID_POINTER;
  567. // This function does NOT appear to have a 16-bit implementation or an
  568. // equivalent thereof.
  569. #ifdef NTONLY
  570. {
  571. if ( NULL != m_pCM_Free_Res_Des_Handle )
  572. {
  573. cr = m_pCM_Free_Res_Des_Handle( rdResDes );
  574. }
  575. }
  576. #endif
  577. return cr;
  578. }
  579. CONFIGRET CConfigMgrAPI::CM_Get_Device_IDA( DEVNODE dnDevNode, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags )
  580. {
  581. CONFIGRET cr = CR_INVALID_POINTER;
  582. #ifdef NTONLY
  583. {
  584. if ( NULL != m_pCM_Get_Device_IDA )
  585. {
  586. cr = m_pCM_Get_Device_IDA( dnDevNode, Buffer, BufferLen, ulFlags );
  587. }
  588. }
  589. #endif
  590. #ifdef WIN9XONLY
  591. {
  592. if ( NULL != m_pCim32NetApi )
  593. {
  594. cr = m_pCim32NetApi->CIM32THK_CM_Get_Device_ID( dnDevNode, Buffer, BufferLen, ulFlags );
  595. }
  596. }
  597. #endif
  598. return cr;
  599. }
  600. CONFIGRET CConfigMgrAPI::CM_Get_Device_ID_Size( PULONG pulLen, DEVNODE dnDevNode, ULONG ulFlags )
  601. {
  602. CONFIGRET cr = CR_INVALID_POINTER;
  603. #ifdef NTONLY
  604. {
  605. if ( NULL != m_pCM_Get_Device_ID_Size )
  606. {
  607. cr = m_pCM_Get_Device_ID_Size( pulLen, dnDevNode, ulFlags );
  608. }
  609. }
  610. #endif
  611. #ifdef WIN9XONLY
  612. {
  613. if ( NULL != m_pCim32NetApi )
  614. {
  615. cr = m_pCim32NetApi->CIM32THK_CM_Get_Device_ID_Size( pulLen, dnDevNode, ulFlags );
  616. }
  617. }
  618. #endif
  619. return cr;
  620. }
  621. #ifdef WIN9XONLY
  622. // This is a 16-bit only function
  623. CONFIGRET CConfigMgrAPI::CM_Get_Bus_Info( DEVNODE dnDevNode, PCMBUSTYPE pbtBusType, LPULONG pulSizeOfInfo, LPVOID pInfo, ULONG ulFlags )
  624. {
  625. CONFIGRET cr = CR_INVALID_POINTER;
  626. {
  627. if ( NULL != m_pCim32NetApi )
  628. {
  629. cr = m_pCim32NetApi->CIM32THK_CM_Get_Bus_Info( dnDevNode, pbtBusType, pulSizeOfInfo, pInfo, ulFlags );
  630. }
  631. }
  632. return cr;
  633. }
  634. CONFIGRET CConfigMgrAPI::CM_Query_Arbitrator_Free_Data(PVOID pData, ULONG DataLen, DEVINST dnDevInst, RESOURCEID ResourceID, ULONG ulFlags)
  635. {
  636. if (m_pCim32NetApi)
  637. {
  638. return m_pCim32NetApi->CIM32THK_CM_Query_Arbitrator_Free_Data(pData, DataLen, dnDevInst, ResourceID, ulFlags);
  639. }
  640. else
  641. {
  642. return CR_INVALID_POINTER;
  643. }
  644. }
  645. CONFIGRET CConfigMgrAPI::CM_Delete_Range(ULONG ulStartValue, ULONG ulEndValue, RANGE_LIST rlh, ULONG ulFlags)
  646. {
  647. if (m_pCim32NetApi)
  648. {
  649. return m_pCim32NetApi->CIM32THK_CM_Delete_Range(ulStartValue, ulEndValue, rlh, ulFlags);
  650. }
  651. else
  652. {
  653. return CR_INVALID_POINTER;
  654. }
  655. }
  656. CONFIGRET CConfigMgrAPI::CM_First_Range(RANGE_LIST rlh, LPULONG pulStart, LPULONG pulEnd, PRANGE_ELEMENT preElement, ULONG ulFlags)
  657. {
  658. if (m_pCim32NetApi)
  659. {
  660. return m_pCim32NetApi->CIM32THK_CM_First_Range(rlh, pulStart, pulEnd, preElement, ulFlags);
  661. }
  662. else
  663. {
  664. return CR_INVALID_POINTER;
  665. }
  666. }
  667. CONFIGRET CConfigMgrAPI::CM_Next_Range(PRANGE_ELEMENT preElement, LPULONG pulStart, LPULONG pullEnd, ULONG ulFlags)
  668. {
  669. if (m_pCim32NetApi)
  670. {
  671. return m_pCim32NetApi->CIM32THK_CM_Next_Range(preElement, pulStart, pullEnd, ulFlags);
  672. }
  673. else
  674. {
  675. return CR_INVALID_POINTER;
  676. }
  677. }
  678. CONFIGRET CConfigMgrAPI::CM_Free_Range_List(RANGE_LIST rlh, ULONG ulFlags)
  679. {
  680. if (m_pCim32NetApi)
  681. {
  682. return m_pCim32NetApi->CIM32THK_CM_Free_Range_List(rlh, ulFlags);
  683. }
  684. else
  685. {
  686. return CR_INVALID_POINTER;
  687. }
  688. }
  689. #endif
  690. BOOL CConfigMgrAPI :: IsValid ()
  691. {
  692. #ifdef WIN9XONLY
  693. return m_pCim32NetApi != NULL;
  694. #endif
  695. #ifdef NTONLY
  696. return m_hConfigMgrDll != NULL;
  697. #endif
  698. }