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.

686 lines
21 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. //
  8. // CookerUtils.cpp
  9. //
  10. #include "precomp.h"
  11. #include <wbemint.h>
  12. #include "cookerutils.h"
  13. #include "strutils.h"
  14. //////////////////////////////////////////////////////////////
  15. //
  16. //
  17. // Helper Functions
  18. //
  19. //
  20. //////////////////////////////////////////////////////////////
  21. BOOL IsCookingClass( IWbemClassObject* pCookingClassObject )
  22. {
  23. HRESULT hResult = WBEM_NO_ERROR;
  24. IWbemQualifierSet *pCookingClassQualifierSet = NULL;
  25. hResult = pCookingClassObject->GetQualifierSet( &pCookingClassQualifierSet );
  26. // Verify "AutoCook" qualifier
  27. // ===========================
  28. if ( SUCCEEDED( hResult ) )
  29. {
  30. CReleaseMe arQualifierSet( (IUnknown*)pCookingClassQualifierSet );
  31. _variant_t vVal;
  32. hResult = pCookingClassQualifierSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &vVal, NULL );
  33. if ( SUCCEEDED( hResult ) )
  34. {
  35. if ( vVal.vt != VT_I4 )
  36. {
  37. hResult = WBEM_E_INVALID_QUALIFIER;
  38. }
  39. else
  40. {
  41. if (WMI_COOKER_VERSION != V_I4(&vVal))
  42. hResult = WBEM_E_INVALID_CLASS;
  43. }
  44. }
  45. }
  46. return SUCCEEDED( hResult );
  47. }
  48. // Table of the counter types and their Cooking type values
  49. struct _CookingTypeRec
  50. {
  51. DWORD dwType;
  52. WCHAR * wcsName;
  53. DWORD dwReqProp;
  54. }
  55. g_aCookingRecs[] =
  56. {
  57. 0x00000000, L"PERF_COUNTER_RAWCOUNT_HEX", REQ_1VALUE,
  58. // BEGIN COOKER_ONLY
  59. 0x00000001, L"COOKER_AVERAGE", REQ_2VALUE,
  60. 0x00000002, L"COOKER_MIN", REQ_2VALUE,
  61. 0x00000003, L"COOKER_MAX", REQ_2VALUE,
  62. 0x00000004, L"COOKER_RANGE", REQ_2VALUE,
  63. 0x00000005, L"COOKER_VARIANCE", REQ_2VALUE,
  64. // END COOKER_ONLY
  65. 0x00000100, L"PERF_COUNTER_LARGE_RAWCOUNT_HEX", REQ_1VALUE,
  66. 0x00000B00, L"PERF_COUNTER_TEXT", REQ_NONE,
  67. 0x00010000, L"PERF_COUNTER_RAWCOUNT", REQ_1VALUE,
  68. 0x00010100, L"PERF_COUNTER_LARGE_RAWCOUNT", REQ_1VALUE,
  69. 0x00012000, L"PERF_DOUBLE_RAW", REQ_1VALUE,
  70. 0x00400400, L"PERF_COUNTER_DELTA", REQ_2VALUE,
  71. 0x00400500, L"PERF_COUNTER_LARGE_DELTA", REQ_2VALUE,
  72. 0x00410400, L"PERF_SAMPLE_COUNTER", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  73. 0x00450400, L"PERF_COUNTER_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  74. 0x00450500, L"PERF_COUNTER_LARGE_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  75. 0x00550500, L"PERF_COUNTER_100NS_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  76. 0x00650500, L"PERF_COUNTER_OBJ_TIME_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  77. 0x10410400, L"PERF_COUNTER_COUNTER", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  78. 0x10410500, L"PERF_COUNTER_BULK_COUNT", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  79. 0x20020400, L"PERF_RAW_FRACTION", REQ_1VALUE|REQ_BASE,
  80. 0x20410500, L"PERF_COUNTER_TIMER", REQ_2VALUE|REQ_TIME,
  81. 0x20470500, L"PERF_PRECISION_SYSTEM_TIMER", REQ_2VALUE|REQ_TIME,
  82. 0x20510500, L"PERF_100NSEC_TIMER", REQ_2VALUE|REQ_TIME,
  83. 0x20570500, L"PERF_PRECISION_100NS_TIMER", REQ_2VALUE|REQ_TIME,
  84. 0x20610500, L"PERF_OBJ_TIME_TIMER", REQ_2VALUE|REQ_TIME,
  85. 0x20670500, L"PERF_PRECISION_OBJECT_TIMER", REQ_2VALUE|REQ_TIME,
  86. 0x20C20400, L"PERF_SAMPLE_FRACTION", REQ_2VALUE|REQ_BASE,
  87. 0x21410500, L"PERF_COUNTER_TIMER_INV", REQ_2VALUE|REQ_TIME,
  88. 0x21510500, L"PERF_100NSEC_TIMER_INV", REQ_2VALUE|REQ_TIME,
  89. 0x22410500, L"PERF_COUNTER_MULTI_TIMER", REQ_2VALUE|REQ_TIME,
  90. 0x22510500, L"PERF_100NSEC_MULTI_TIMER", REQ_2VALUE|REQ_TIME,
  91. 0x23410500, L"PERF_COUNTER_MULTI_TIMER_INV", REQ_2VALUE|REQ_TIME,
  92. 0x23510500, L"PERF_100NSEC_MULTI_TIMER_INV", REQ_2VALUE|REQ_TIME,
  93. 0x30020400, L"PERF_AVERAGE_TIMER", REQ_2VALUE|REQ_BASE|REQ_FREQ,
  94. 0x30240500, L"PERF_ELAPSED_TIME", REQ_1VALUE|REQ_TIME|REQ_FREQ,
  95. 0x40000200, L"PERF_COUNTER_NODATA", REQ_NONE,
  96. 0x40020500, L"PERF_AVERAGE_BULK", REQ_2VALUE|REQ_BASE,
  97. 0x40030401, L"PERF_SAMPLE_BASE", REQ_NONE,
  98. 0x40030402, L"PERF_AVERAGE_BASE", REQ_NONE,
  99. 0x40030403, L"PERF_RAW_BASE", REQ_NONE,
  100. 0x40030500, L"PERF_PRECISION_TIMESTAMP", REQ_NONE,
  101. 0x40030503, L"PERF_LARGE_RAW_BASE", REQ_NONE,
  102. 0x42030500, L"PERF_COUNTER_MULTI_BASE", REQ_NONE,
  103. 0x80000000, L"PERF_COUNTER_HISTOGRAM_TYPE", REQ_NONE,
  104. };
  105. //
  106. //
  107. // performs a linear search in the above array
  108. //
  109. /////////////////////////////////////////////
  110. HRESULT FindCounterType( WCHAR* pwcsString, DWORD* pdwType, DWORD *pdwReqProp)
  111. {
  112. HRESULT hRes = WBEM_S_NO_ERROR;
  113. DWORD dwLeft = 0,
  114. dwRight = sizeof( g_aCookingRecs ) / sizeof( _CookingTypeRec );
  115. while ( ( dwLeft < dwRight ) && SUCCEEDED( hRes ) )
  116. {
  117. // Found it
  118. if ( wbem_wcsicmp( g_aCookingRecs[dwLeft].wcsName, pwcsString ) == 0 )
  119. {
  120. *pdwType = g_aCookingRecs[dwLeft].dwType;
  121. *pdwReqProp = g_aCookingRecs[dwLeft].dwReqProp;
  122. break;
  123. }
  124. dwLeft++;
  125. }
  126. if ( dwLeft >= dwRight )
  127. {
  128. hRes = WBEM_E_NOT_FOUND;
  129. }
  130. return hRes;
  131. }
  132. //
  133. //
  134. // TRUE if a class has the singleton qualifier set to VARIANT_TRUE
  135. //
  136. ////////////////////////////////////////////
  137. BOOL IsSingleton(IWbemClassObject * pCls)
  138. {
  139. if (pCls)
  140. {
  141. HRESULT hr;
  142. IWbemQualifierSet * pQS = NULL;
  143. if (SUCCEEDED(hr = pCls->GetQualifierSet(&pQS)))
  144. {
  145. CReleaseMe rm1(pQS);
  146. _variant_t VarBool;
  147. hr = pQS->Get(L"singleton",0,&VarBool,NULL);
  148. if (SUCCEEDED(hr) &&
  149. VarBool.vt == VT_BOOL &&
  150. V_BOOL(&VarBool) == VARIANT_TRUE)
  151. {
  152. return TRUE;
  153. }
  154. }
  155. }
  156. return FALSE;
  157. }
  158. //
  159. // returns TRUE if the property qualifier set has the CookingType
  160. // qualifier and if the CookingType is recognized
  161. //
  162. ///////////////////////////////////////////////////////////////////
  163. BOOL IsCookingProperty( BSTR strPropName, IWbemClassObject* pCookingClassObject, DWORD* pdwCounterType, DWORD * pdwReqProp )
  164. {
  165. HRESULT hResult = WBEM_NO_ERROR;
  166. IWbemQualifierSet* pPropQualSet = NULL;
  167. _variant_t vVal;
  168. hResult = pCookingClassObject->GetPropertyQualifierSet( (LPCWSTR)strPropName, &pPropQualSet );
  169. if ( SUCCEEDED( hResult ) )
  170. {
  171. CReleaseMe arPropQualSet( (IUnknown*)pPropQualSet );
  172. hResult = pPropQualSet->Get( WMI_COOKER_COOKING_PROPERTY_ATTRIBUTE, 0, &vVal, NULL );
  173. if ( SUCCEEDED ( hResult ) )
  174. {
  175. if ( vVal.vt == VT_BSTR )
  176. {
  177. hResult = FindCounterType( V_BSTR( &vVal ), pdwCounterType, pdwReqProp );
  178. }
  179. else
  180. {
  181. hResult = E_FAIL;
  182. }
  183. }
  184. }
  185. return SUCCEEDED( hResult );
  186. }
  187. //
  188. //
  189. // returns the portion of __RELPATH past the '=' sign
  190. // return NULL in case of failure
  191. //
  192. ///////////////////////////////////////////////////////////////////////////////
  193. LPWSTR GetKey( IWbemObjectAccess* pClassObj )
  194. {
  195. WMISTATUS dwStatus = WBEM_NO_ERROR;
  196. LPWSTR wszKeyName = NULL;
  197. LPWSTR wszTempKeyPtr = NULL;
  198. _variant_t var;
  199. dwStatus = pClassObj->Get( L"__RELPATH", 0, &var, NULL, NULL );
  200. if ( SUCCEEDED( dwStatus ) )
  201. {
  202. if ( var.vt != VT_BSTR )
  203. {
  204. dwStatus = WBEM_E_FAILED;
  205. }
  206. else
  207. {
  208. wszTempKeyPtr = wcsstr( var.bstrVal, L"=" );
  209. wszTempKeyPtr++;
  210. size_t length = wcslen( wszTempKeyPtr ) + 1 ;
  211. wszKeyName = new WCHAR[ length];
  212. if (wszKeyName)
  213. StringCchCopyW( wszKeyName, length , wszTempKeyPtr );
  214. else
  215. {
  216. // returns NULL
  217. }
  218. }
  219. }
  220. return wszKeyName;
  221. }
  222. WMISTATUS CopyBlob( IWbemClassObject* pSource, IWbemClassObject* pTarget )
  223. {
  224. HRESULT dwStatus = E_NOINTERFACE ;
  225. HRESULT hr1,hr2;
  226. _IWmiObject* pIntTarget = NULL;
  227. _IWmiObject* pIntSource = NULL;
  228. hr1 = pTarget->QueryInterface( IID__IWmiObject, (void**)&pIntTarget );
  229. CReleaseMe arIntTarget( pIntTarget );
  230. hr2 = pSource->QueryInterface( IID__IWmiObject, (void**)&pIntSource );
  231. CReleaseMe arIntSource( pIntSource );
  232. if ( SUCCEEDED(hr1) && SUCCEEDED(hr2) )
  233. {
  234. dwStatus = pIntTarget->CopyInstanceData( 0L, pIntSource );
  235. }
  236. return dwStatus;
  237. }
  238. //
  239. //
  240. // TRUE if the class/instance derives from Win32_PerfFormattedData
  241. //
  242. /////////////////////////////////////
  243. BOOL IsHiPerfObj(IWbemObjectAccess* pObject)
  244. {
  245. _variant_t Var;
  246. HRESULT hr = pObject->Get(L"__SUPERCLASS",0,&Var,NULL,NULL);
  247. if (SUCCEEDED(hr))
  248. {
  249. if (Var.vt == VT_BSTR)
  250. hr = (0 == wbem_wcsicmp(Var.bstrVal,L"Win32_PerfFormattedData"))?S_OK:E_FAIL;
  251. else
  252. hr = E_FAIL;
  253. }
  254. return SUCCEEDED(hr);
  255. }
  256. //
  257. //
  258. // TRUE if an object has the required qualifier to
  259. // be regarded as an HiPerf CWebminstance
  260. //
  261. ////////////////////////////////////////////////
  262. BOOL IsHiPerf( IWbemObjectAccess* pObject )
  263. {
  264. WMISTATUS hr = WBEM_NO_ERROR;
  265. IWbemQualifierSet* pQualSet = NULL;
  266. hr = pObject->GetQualifierSet( &pQualSet );
  267. CReleaseMe arQualSet( pQualSet );
  268. // Verify the "Hiperf" class qualifier
  269. if (SUCCEEDED(hr))
  270. {
  271. _variant_t var;
  272. hr = pQualSet->Get( WMI_COOKER_HIPERF_QUALIFIER, 0, &var, NULL );
  273. if ( SUCCEEDED(hr) && ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) ) )
  274. {
  275. hr = WBEM_E_INVALID_QUALIFIER;
  276. }
  277. }
  278. // Verify the "Cooked" class qualifier
  279. if (SUCCEEDED(hr))
  280. {
  281. _variant_t var;
  282. hr = pQualSet->Get( WMI_COOKER_COOKING_QUALIFIER, 0, &var, NULL );
  283. if ( SUCCEEDED(hr) && ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) ) )
  284. {
  285. hr = WBEM_E_INVALID_QUALIFIER;
  286. }
  287. }
  288. // Verify the "AutoCook" class qualifier
  289. if (SUCCEEDED(hr))
  290. {
  291. _variant_t var;
  292. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &var, NULL );
  293. if (SUCCEEDED(hr))
  294. {
  295. if ( var.vt != VT_I4 )
  296. {
  297. hr = WBEM_E_INVALID_QUALIFIER;
  298. }
  299. else
  300. {
  301. if (WMI_COOKER_VERSION != V_I4(&var))
  302. hr = WBEM_E_INVALID_CLASS;
  303. }
  304. }
  305. }
  306. // Verify the "AutoCook_RawClass" class qualifier
  307. if (SUCCEEDED(hr))
  308. {
  309. _variant_t var;
  310. hr = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &var, NULL );
  311. if ( SUCCEEDED(hr) && ( var.vt != VT_BSTR ) )
  312. {
  313. hr = WBEM_E_INVALID_QUALIFIER;
  314. }
  315. }
  316. // verify the "AutoCook_RawDeafult" class qualifier if there
  317. if (SUCCEEDED(hr))
  318. {
  319. _variant_t var;
  320. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_RAWDEFAULT, 0, &var, NULL );
  321. if ( SUCCEEDED(hr) )
  322. {
  323. if ((var.vt != VT_I4) ||
  324. (V_I4(&var) != AUTOCOOK_RAWDEFAULT_CURRENT_ACCEPTED))
  325. {
  326. hr = WBEM_E_INVALID_QUALIFIER;
  327. }
  328. else // good qualifier, see the properties
  329. {
  330. HRESULT hr1 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_PERFTIME,0,NULL,NULL,NULL);
  331. HRESULT hr2 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_SYS100NS,0,NULL,NULL,NULL);
  332. HRESULT hr3 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_OBJECT ,0,NULL,NULL,NULL);
  333. HRESULT hr4 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_PERFTIME,0,NULL,NULL,NULL);
  334. HRESULT hr5 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_SYS100NS,0,NULL,NULL,NULL);
  335. HRESULT hr6 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_OBJECT ,0,NULL,NULL,NULL);
  336. if (SUCCEEDED(hr1) &&
  337. SUCCEEDED(hr2) &&
  338. SUCCEEDED(hr3) &&
  339. SUCCEEDED(hr4) &&
  340. SUCCEEDED(hr5) &&
  341. SUCCEEDED(hr6))
  342. {
  343. // ok
  344. }
  345. else
  346. {
  347. hr = WBEM_E_INVALID_CLASS;
  348. }
  349. }
  350. }
  351. else
  352. {
  353. // this qualifier is optional
  354. hr = WBEM_NO_ERROR;
  355. }
  356. }
  357. return SUCCEEDED(hr);
  358. }
  359. //
  360. //
  361. // TRUE if the given path points to a class has the required qualifier to
  362. // be regarded as an HiPerf class
  363. // it also verifies that the AutoCook_RawClass indeed exists and it is hiperf
  364. //
  365. ////////////////////////////////////////////////
  366. BOOL IsHiPerf( IWbemServices* pNamespace, LPCWSTR wszObject )
  367. {
  368. IWbemClassObject* pObject = NULL;
  369. // Get the WMI object
  370. BSTR strObject = SysAllocString(wszObject);
  371. if (NULL == strObject) return FALSE;
  372. CSysFreeMe fme(strObject);
  373. HRESULT hr = pNamespace->GetObject( strObject, 0, NULL, &pObject, NULL );
  374. CReleaseMe arObject( pObject );
  375. if (SUCCEEDED(hr))
  376. {
  377. IWbemQualifierSet* pQualSet = NULL;
  378. hr = pObject->GetQualifierSet( &pQualSet );
  379. CReleaseMe arQualSet( pQualSet );
  380. // Verify the "Hiperf" class qualifier
  381. if ( SUCCEEDED(hr) )
  382. {
  383. _variant_t var;
  384. hr = pQualSet->Get( WMI_COOKER_HIPERF_QUALIFIER, 0, &var, NULL );
  385. if ( SUCCEEDED(hr) &&
  386. ( (var.vt != VT_BOOL) ||
  387. (var.boolVal != VARIANT_TRUE)) )
  388. {
  389. hr = WBEM_E_INVALID_QUALIFIER;
  390. }
  391. }
  392. // Verify the "Cooked" class qualifier
  393. if ( SUCCEEDED(hr) )
  394. {
  395. _variant_t var;
  396. hr = pQualSet->Get( WMI_COOKER_COOKING_QUALIFIER, 0, &var, NULL );
  397. if ( SUCCEEDED(hr) &&
  398. ( (var.vt != VT_BOOL) ||
  399. (var.boolVal != VARIANT_TRUE)) )
  400. {
  401. hr = WBEM_E_INVALID_QUALIFIER;
  402. }
  403. }
  404. // Verify the "AutoCook" class qualifier
  405. if ( SUCCEEDED(hr) )
  406. {
  407. _variant_t var;
  408. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &var, NULL );
  409. if ( SUCCEEDED(hr) )
  410. {
  411. if (var.vt != VT_I4 )
  412. {
  413. hr = WBEM_E_INVALID_QUALIFIER;
  414. }
  415. else
  416. {
  417. if (WMI_COOKER_VERSION != V_I4(&var))
  418. hr = WBEM_E_INVALID_CLASS;
  419. }
  420. }
  421. }
  422. // Verify the "AutoCook_RawClass" class qualifier
  423. // ==============================================
  424. if ( SUCCEEDED(hr) )
  425. {
  426. _variant_t varRawClass;
  427. hr = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &varRawClass, NULL );
  428. if ( SUCCEEDED(hr) )
  429. {
  430. if ( varRawClass.vt == VT_BSTR )
  431. {
  432. IWbemClassObject * pRawClass = NULL;
  433. hr = pNamespace->GetObject(V_BSTR(&varRawClass),0,NULL,&pRawClass,NULL);
  434. CReleaseMe rm1(pRawClass);
  435. if (SUCCEEDED(hr))
  436. {
  437. IWbemQualifierSet * pQS = NULL;
  438. hr = pRawClass->GetQualifierSet(&pQS);
  439. CReleaseMe rm2(pQS);
  440. if (SUCCEEDED(hr))
  441. {
  442. // verify the hiperf qualifier on the RAW class
  443. _variant_t varH;
  444. hr = pQS->Get(WMI_COOKER_HIPERF_QUALIFIER, 0, &varH, NULL);
  445. if ( SUCCEEDED(hr) &&
  446. ( (varH.vt != VT_BOOL) ||
  447. (varH.boolVal != VARIANT_TRUE)) )
  448. {
  449. hr = WBEM_E_INVALID_QUALIFIER;
  450. };
  451. }
  452. }
  453. else
  454. {
  455. hr = WBEM_E_INVALID_CLASS;
  456. }
  457. }
  458. else
  459. {
  460. hr = WBEM_E_INVALID_QUALIFIER;
  461. }
  462. }
  463. }
  464. // verify the "AutoCook_RawDeafult" class qualifier if there
  465. // ==========================================================
  466. if ( SUCCEEDED(hr) )
  467. {
  468. _variant_t var;
  469. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_RAWDEFAULT, 0, &var, NULL );
  470. if ( SUCCEEDED(hr) )
  471. {
  472. if ((var.vt != VT_I4) ||
  473. (V_I4(&var) != AUTOCOOK_RAWDEFAULT_CURRENT_ACCEPTED))
  474. {
  475. hr = WBEM_E_INVALID_QUALIFIER;
  476. }
  477. else // good qualifier, see the properties
  478. {
  479. HRESULT hr1 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_PERFTIME,0,NULL,NULL,NULL);
  480. HRESULT hr2 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_SYS100NS,0,NULL,NULL,NULL);
  481. HRESULT hr3 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_OBJECT ,0,NULL,NULL,NULL);
  482. HRESULT hr4 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_PERFTIME,0,NULL,NULL,NULL);
  483. HRESULT hr5 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_SYS100NS,0,NULL,NULL,NULL);
  484. HRESULT hr6 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_OBJECT ,0,NULL,NULL,NULL);
  485. if (SUCCEEDED(hr1) &&
  486. SUCCEEDED(hr2) &&
  487. SUCCEEDED(hr3) &&
  488. SUCCEEDED(hr4) &&
  489. SUCCEEDED(hr5) &&
  490. SUCCEEDED(hr6))
  491. {
  492. // ok
  493. }
  494. else
  495. {
  496. hr = WBEM_E_INVALID_CLASS;
  497. }
  498. }
  499. }
  500. else
  501. {
  502. // this qualifier is optional
  503. hr = WBEM_NO_ERROR;
  504. }
  505. }
  506. return SUCCEEDED(hr);
  507. }
  508. return FALSE;
  509. }
  510. //
  511. //
  512. // returns pCookingInst->GetQualifierSet()->Get(L"AutoCook_RawClass")
  513. //
  514. //////////////////////////////////
  515. WMISTATUS GetRawClassName( IWbemClassObject* pCookingInst, WCHAR** pwszRawClassName )
  516. {
  517. WMISTATUS dwStatus = WBEM_NO_ERROR;
  518. IWbemQualifierSet* pQualSet = NULL; // The Instance qualifier set
  519. _variant_t varRawInstName; // The raw instance name
  520. dwStatus = pCookingInst->GetQualifierSet( &pQualSet );
  521. CReleaseMe adQualSet( pQualSet );
  522. if ( SUCCEEDED( dwStatus ) )
  523. {
  524. dwStatus = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &varRawInstName, NULL );
  525. if ( SUCCEEDED( dwStatus ) )
  526. {
  527. if ( VT_BSTR == varRawInstName.vt )
  528. {
  529. size_t length = wcslen( varRawInstName.bstrVal ) + 1;
  530. WCHAR* wszRawClassName = new WCHAR[length];
  531. if ( NULL != wszRawClassName )
  532. {
  533. StringCchCopyW( wszRawClassName, length , varRawInstName.bstrVal);
  534. *pwszRawClassName = wszRawClassName;
  535. }
  536. else
  537. {
  538. dwStatus = WBEM_E_OUT_OF_MEMORY;
  539. }
  540. }
  541. else
  542. {
  543. dwStatus = WBEM_E_TYPE_MISMATCH;
  544. }
  545. }
  546. }
  547. return dwStatus;
  548. }
  549. //
  550. //
  551. // returns pAccess->Get("__CLASS")
  552. //
  553. //////////////////////////////////
  554. WMISTATUS GetClassName( IWbemObjectAccess* pAccess, WCHAR** pwszClassName )
  555. {
  556. _variant_t vVal;
  557. WMISTATUS dwStatus = pAccess->Get(L"__CLASS", 0, &vVal, NULL, NULL );
  558. if ( VT_BSTR != V_VT(&vVal) )
  559. {
  560. dwStatus = E_FAIL;
  561. }
  562. if ( SUCCEEDED( dwStatus ) )
  563. {
  564. size_t length = wcslen( vVal.bstrVal ) + 1;
  565. WCHAR* wszClassName = new WCHAR[ length ];
  566. if ( wszClassName )
  567. {
  568. StringCchCopyW( wszClassName, length , vVal.bstrVal );
  569. *pwszClassName = wszClassName;
  570. }
  571. else
  572. {
  573. dwStatus = WBEM_E_OUT_OF_MEMORY;
  574. }
  575. }
  576. return dwStatus;
  577. }