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.

764 lines
22 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. CBMOFOUT.CPP
  5. Abstract:
  6. Declares the CBMOFOut class.
  7. History:
  8. a-davj 06-April-97 Created.
  9. --*/
  10. #include "precomp.h"
  11. #include "wstring.h"
  12. #include "mofout.h"
  13. #include "mofdata.h"
  14. #include "bmof.h"
  15. #include "cbmofout.h"
  16. #include "trace.h"
  17. #include "strings.h"
  18. #include <wbemutil.h>
  19. //***************************************************************************
  20. //
  21. // CBMOFOut::CBMOFOut
  22. //
  23. // DESCRIPTION:
  24. //
  25. // Constructor. Save the eventual destination name and writes the initial
  26. // structure out to the buffer. NOTE THAT TYPICALLY THE BMOFFileName will
  27. // be NULL and this object will not do anything. That deals with the 99%
  28. // of mofs that are not WMI!
  29. //
  30. // PARAMETERS:
  31. //
  32. // BMOFFileName Name of file to eventually write to.
  33. //
  34. //***************************************************************************
  35. CBMOFOut::CBMOFOut(
  36. IN LPTSTR BMOFFileName, PDBG pDbg) : m_OutBuff(pDbg)
  37. {
  38. m_pDbg = pDbg;
  39. m_BinMof.dwSignature = BMOF_SIG; // spells BMOF
  40. m_BinMof.dwLength = sizeof(WBEM_Binary_MOF); // updated at end
  41. m_BinMof.dwVersion = 1; // 0x1
  42. m_BinMof.dwEncoding = 1; // 0x1 = little endian, DWORD-aligned, no compression
  43. m_BinMof.dwNumberOfObjects = 0; // Total classes and instances in MOF
  44. if(BMOFFileName && lstrlen(BMOFFileName) > 0)
  45. {
  46. DWORD dwLen = lstrlen(BMOFFileName) + 1;
  47. m_pFile = new TCHAR[dwLen];
  48. if(m_pFile)
  49. {
  50. StringCchCopyW(m_pFile, dwLen, BMOFFileName);
  51. m_OutBuff.AppendBytes((BYTE *)&m_BinMof, sizeof(WBEM_Binary_MOF));
  52. }
  53. }
  54. else
  55. m_pFile = NULL;
  56. }
  57. //***************************************************************************
  58. //
  59. // CBMOFOut::~CBMOFOut
  60. //
  61. // DESCRIPTION:
  62. //
  63. // Destructor.
  64. //
  65. //***************************************************************************
  66. CBMOFOut::~CBMOFOut()
  67. {
  68. if(m_pFile)
  69. delete m_pFile;
  70. }
  71. //***************************************************************************
  72. //
  73. // DWORD CBMOFOut::AddClass
  74. //
  75. // DESCRIPTION:
  76. //
  77. // Adds a class to the BMOF buffer.
  78. //
  79. // PARAMETERS:
  80. //
  81. // pObject pointer to class object.
  82. // bEmbedded TRUE if object is embedded.
  83. //
  84. // RETURN VALUE:
  85. //
  86. // Number of bytes written.
  87. //
  88. //***************************************************************************
  89. DWORD CBMOFOut::AddClass(
  90. IN CMObject * pObject,
  91. IN BOOL bEmbedded)
  92. {
  93. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  94. CMoQualifierArray * pQualifierSet = NULL;
  95. if(!m_pFile)
  96. return 0;
  97. WBEM_Object wo;
  98. wo.dwLength = sizeof(WBEM_Object); // updated later
  99. wo.dwOffsetQualifierList = 0xffffffff;
  100. wo.dwOffsetPropertyList = 0xffffffff;
  101. wo.dwOffsetMethodList = 0xffffffff;
  102. wo.dwType = (pObject->IsInstance()) ? 1 : 0; // 0 = class, 1 = instance
  103. m_OutBuff.AppendBytes((BYTE *)&wo, sizeof(WBEM_Object));
  104. DWORD dwStartInfoOffset = m_OutBuff.GetOffset();
  105. // Write class qualifier
  106. pQualifierSet = pObject->GetQualifiers();
  107. if(pQualifierSet)
  108. {
  109. wo.dwOffsetQualifierList = m_OutBuff.GetOffset() - dwStartInfoOffset;
  110. AddQualSet(pQualifierSet);
  111. }
  112. wo.dwOffsetPropertyList = m_OutBuff.GetOffset() - dwStartInfoOffset;
  113. AddPropSet(pObject);
  114. wo.dwOffsetMethodList = m_OutBuff.GetOffset() - dwStartInfoOffset;
  115. AddMethSet(pObject);
  116. wo.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  117. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&wo, sizeof(WBEM_Object));
  118. // If the object is not embedded, update the structure that keeps track
  119. // of top level objects.
  120. if(!bEmbedded)
  121. {
  122. m_BinMof.dwNumberOfObjects++;
  123. m_BinMof.dwLength = m_OutBuff.GetOffset();
  124. m_OutBuff.WriteBytes(0, (BYTE *)&m_BinMof,
  125. sizeof(WBEM_Binary_MOF));
  126. }
  127. return wo.dwLength;
  128. }
  129. //***************************************************************************
  130. //
  131. // DWORD CBMOFOut::AddQualSet
  132. //
  133. // DESCRIPTION:
  134. //
  135. // Adds a qualifier set to the BMOF buffer.
  136. //
  137. // PARAMETERS:
  138. //
  139. // pQualifierSet pointer to qualifier object.
  140. //
  141. // RETURN VALUE:
  142. //
  143. // Number of bytes written.
  144. //
  145. //***************************************************************************
  146. DWORD CBMOFOut::AddQualSet(
  147. IN CMoQualifierArray * pQualifierSet)
  148. {
  149. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  150. WBEM_QualifierList ql;
  151. ql.dwLength = sizeof(WBEM_QualifierList);
  152. ql.dwNumQualifiers = 0;
  153. m_OutBuff.AppendBytes((BYTE *)&ql, sizeof(WBEM_QualifierList));
  154. BSTR bstr = NULL;
  155. VARIANT var;
  156. VariantInit(&var);
  157. int i;
  158. for(i = 0; i < pQualifierSet->GetSize(); i++)
  159. {
  160. CMoQualifier * pQual = pQualifierSet->GetAt(i);
  161. if(pQual)
  162. {
  163. ql.dwNumQualifiers++;
  164. AddQualifier(pQual->GetName(), pQual->GetpVar(), pQual);
  165. }
  166. }
  167. ql.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  168. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&ql,
  169. sizeof(WBEM_QualifierList));
  170. return ql.dwLength;
  171. }
  172. //***************************************************************************
  173. //
  174. // DWORD CBMOFOut::AddPropSet
  175. //
  176. // DESCRIPTION:
  177. //
  178. // Adds the property set to the BMOF buffer.
  179. //
  180. // PARAMETERS:
  181. //
  182. // pObject pointer to class object.
  183. //
  184. // RETURN VALUE:
  185. //
  186. // Number of bytess written
  187. //
  188. //***************************************************************************
  189. DWORD CBMOFOut::AddPropSet(
  190. IN CMObject * pObject)
  191. {
  192. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  193. WBEM_PropertyList pl;
  194. BSTR bstr = NULL;
  195. VARIANT var;
  196. VariantInit(&var);
  197. IWbemQualifierSet* pQual = NULL;
  198. pl.dwLength = sizeof(WBEM_PropertyList); // updated later
  199. pl.dwNumberOfProperties = 0;
  200. m_OutBuff.AppendBytes((BYTE *)&pl, sizeof(WBEM_PropertyList));
  201. // Loop through the properties
  202. int i;
  203. for(i = 0; i < pObject->GetNumProperties(); i++)
  204. {
  205. CMoProperty * pProp = pObject->GetProperty(i);
  206. if(pProp && pProp->IsValueProperty())
  207. {
  208. pl.dwNumberOfProperties++;
  209. CMoQualifierArray * pQual = pProp->GetQualifiers();
  210. AddProp(pProp->GetName(), pProp->GetpVar(), pQual,pProp->GetType(),pProp);
  211. }
  212. }
  213. // Store the class name and possibly the parent name as properties.
  214. VariantInit(&var);
  215. var.vt = VT_BSTR;
  216. var.bstrVal = SysAllocString(pObject->GetClassName());
  217. AddProp(L"__CLASS", &var, NULL,VT_BSTR,NULL);
  218. pl.dwNumberOfProperties++;
  219. VariantClear(&var);
  220. if(pObject->GetNamespace() && wcslen(pObject->GetNamespace()) > 0)
  221. {
  222. VariantInit(&var);
  223. var.vt = VT_BSTR;
  224. var.bstrVal = SysAllocString(pObject->GetNamespace());
  225. AddProp(L"__NAMESPACE", &var, NULL,VT_BSTR,NULL);
  226. pl.dwNumberOfProperties++;
  227. VariantClear(&var);
  228. }
  229. if(pObject->GetClassFlags() != 0)
  230. {
  231. VariantInit(&var);
  232. var.vt = VT_I4;
  233. var.lVal = pObject->GetClassFlags();
  234. AddProp(L"__CLASSFLAGS", &var, NULL,VT_I4,NULL);
  235. pl.dwNumberOfProperties++;
  236. VariantClear(&var);
  237. }
  238. if(pObject->GetInstanceFlags() != 0)
  239. {
  240. VariantInit(&var);
  241. var.vt = VT_I4;
  242. var.lVal = pObject->GetInstanceFlags();
  243. AddProp(L"__INSTANCEFLAGS", &var, NULL,VT_I4,NULL);
  244. pl.dwNumberOfProperties++;
  245. VariantClear(&var);
  246. }
  247. if(pObject->GetAlias() && wcslen(pObject->GetAlias()) > 0)
  248. {
  249. VariantInit(&var);
  250. var.vt = VT_BSTR;
  251. var.bstrVal = SysAllocString(pObject->GetAlias());
  252. AddProp(L"__ALIAS", &var, NULL,VT_BSTR,NULL);
  253. pl.dwNumberOfProperties++;
  254. VariantClear(&var);
  255. }
  256. if(!pObject->IsInstance())
  257. {
  258. CMoClass * pClass = (CMoClass * )pObject;
  259. var.vt = VT_BSTR;
  260. if(pClass->GetParentName() && wcslen(pClass->GetParentName()) > 0)
  261. {
  262. var.bstrVal = SysAllocString(pClass->GetParentName());
  263. AddProp(L"__SUPERCLASS", &var, NULL,VT_BSTR,NULL);
  264. pl.dwNumberOfProperties++;
  265. VariantClear(&var);
  266. }
  267. };
  268. pl.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  269. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&pl,
  270. sizeof(WBEM_PropertyList));
  271. return pl.dwLength;
  272. }
  273. //***************************************************************************
  274. //
  275. // DWORD CBMOFOut::AddMethSet
  276. //
  277. // DESCRIPTION:
  278. //
  279. // Adds the method set to the BMOF buffer.
  280. //
  281. // PARAMETERS:
  282. //
  283. // pObject pointer to class object.
  284. //
  285. // RETURN VALUE:
  286. //
  287. // Number of bytess written
  288. //
  289. //***************************************************************************
  290. DWORD CBMOFOut::AddMethSet(
  291. IN CMObject * pObject)
  292. {
  293. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  294. WBEM_PropertyList ml;
  295. SCODE sc;
  296. IWbemQualifierSet* pQual = NULL;
  297. ml.dwLength = sizeof(WBEM_PropertyList); // updated later
  298. ml.dwNumberOfProperties = 0;
  299. m_OutBuff.AppendBytes((BYTE *)&ml, sizeof(WBEM_PropertyList));
  300. // Loop through the properties
  301. int i;
  302. for(i = 0; i < pObject->GetNumProperties(); i++)
  303. {
  304. CMoProperty * pProp = pObject->GetProperty(i);
  305. if(pProp && !pProp->IsValueProperty())
  306. {
  307. ml.dwNumberOfProperties++;
  308. CMoQualifierArray * pQual = pProp->GetQualifiers();
  309. // Create a variant that has an array of embedded object for each of out
  310. // input and output arg sets
  311. CMethodProperty * pMeth = (CMethodProperty *)pProp;
  312. VARIANT vSet;
  313. if(pMeth->GetInObj() || pMeth->GetOutObj())
  314. {
  315. vSet.vt = VT_ARRAY | VT_EMBEDDED_OBJECT;
  316. SAFEARRAYBOUND aBounds[1];
  317. // Note the you might have either inputs, or ouputs, or both
  318. if(pMeth->GetInObj() && pMeth->GetOutObj())
  319. aBounds[0].cElements = 2;
  320. else
  321. aBounds[0].cElements = 1;
  322. aBounds[0].lLbound = 0;
  323. #ifdef _WIN64
  324. vSet.parray = SafeArrayCreate(VT_R8, 1, aBounds);
  325. #else
  326. vSet.parray = SafeArrayCreate(VT_I4, 1, aBounds);
  327. #endif
  328. if(vSet.parray == NULL)
  329. return FALSE;
  330. long lIndex = 0;
  331. VARIANT var;
  332. if(pMeth->GetInObj())
  333. {
  334. var.punkVal = (IUnknown *)pMeth->GetInObj();
  335. sc = SafeArrayPutElement(vSet.parray, &lIndex, &var.punkVal);
  336. lIndex = 1;
  337. }
  338. if(pMeth->GetOutObj())
  339. {
  340. var.punkVal = (IUnknown *)pMeth->GetOutObj();
  341. sc = SafeArrayPutElement(vSet.parray, &lIndex, &var.punkVal);
  342. }
  343. }
  344. else
  345. vSet.vt = VT_NULL;
  346. AddProp(pProp->GetName(), &vSet, pQual,pProp->GetType(),pProp);
  347. }
  348. }
  349. ml.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  350. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&ml,
  351. sizeof(WBEM_PropertyList));
  352. return ml.dwLength;
  353. }
  354. //***************************************************************************
  355. //
  356. // DWORD CBMOFOut::AddProp
  357. //
  358. // DESCRIPTION:
  359. //
  360. // Adds a single property to the BMOF buffer.
  361. //
  362. // PARAMETERS:
  363. //
  364. // bstr property name
  365. // pvar variant containing value
  366. // pQual pointer to qualifier set if any. Caller will release.
  367. // dwType data type. Note that the variant might have type
  368. // VT_NULL if the property doesnt have a value.
  369. // RETURN VALUE:
  370. //
  371. // Number of bytes written
  372. //
  373. //***************************************************************************
  374. DWORD CBMOFOut::AddProp(
  375. IN BSTR bstr,
  376. IN VARIANT * pvar,
  377. IN CMoQualifierArray * pQual,
  378. IN DWORD dwType,
  379. IN CMoProperty * pProp)
  380. {
  381. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  382. WBEM_Property prop;
  383. prop.dwLength = sizeof(WBEM_Property);
  384. if(pvar->vt == VT_NULL || pvar->vt == VT_EMPTY)
  385. prop.dwType = dwType;
  386. else
  387. prop.dwType = pvar->vt;
  388. prop.dwOffsetName = 0xffffffff;
  389. prop.dwOffsetValue = 0xffffffff;
  390. prop.dwOffsetQualifierSet = 0xffffffff;
  391. m_OutBuff.AppendBytes((BYTE *)&prop, sizeof(WBEM_Property));
  392. DWORD dwStartInfoOffset = m_OutBuff.GetOffset();
  393. if(bstr)
  394. {
  395. prop.dwOffsetName = m_OutBuff.GetOffset() - dwStartInfoOffset;
  396. m_OutBuff.WriteBSTR(bstr);
  397. }
  398. if(pvar->vt != VT_EMPTY && pvar->vt != VT_NULL)
  399. {
  400. prop.dwOffsetValue = m_OutBuff.GetOffset() - dwStartInfoOffset;
  401. if(pProp)
  402. {
  403. CMoValue& Value = pProp->AccessValue();
  404. AddVariant(pvar, &Value);
  405. prop.dwType = pvar->vt;
  406. }
  407. else
  408. AddVariant(pvar, NULL);
  409. }
  410. if(pQual)
  411. {
  412. prop.dwOffsetQualifierSet = m_OutBuff.GetOffset() - dwStartInfoOffset;
  413. AddQualSet(pQual);
  414. }
  415. prop.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  416. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&prop,
  417. sizeof(WBEM_Property));
  418. return 1;
  419. }
  420. //***************************************************************************
  421. //
  422. // DWORD CBMOFOut::AddQualifier
  423. //
  424. // DESCRIPTION:
  425. //
  426. // Adds a qualifier to the BMOF buffer.
  427. //
  428. // PARAMETERS:
  429. //
  430. // bstr qualifer name
  431. // pvar qualifier value
  432. //
  433. // RETURN VALUE:
  434. //
  435. // Number of bytes written.
  436. //
  437. //***************************************************************************
  438. DWORD CBMOFOut::AddQualifier(
  439. IN BSTR bstr,
  440. IN VARIANT * pvar,
  441. CMoQualifier * pQual)
  442. {
  443. WBEM_Qualifier qu;
  444. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  445. long lFlavor = pQual->GetFlavor();
  446. if(pQual->IsAmended())
  447. lFlavor |= WBEM_FLAVOR_AMENDED;
  448. if(lFlavor)
  449. m_OutBuff.AddFlavor(lFlavor);
  450. qu.dwLength = sizeof(WBEM_Qualifier); // filled in later
  451. qu.dwType = pvar->vt;
  452. qu.dwOffsetName = 0xffffffff;
  453. qu.dwOffsetValue = 0xffffffff;
  454. m_OutBuff.AppendBytes((BYTE *)&qu, sizeof(WBEM_Qualifier));
  455. DWORD dwStartInfoOffset = m_OutBuff.GetOffset();
  456. // Write the qualifier name and data
  457. if(bstr)
  458. {
  459. qu.dwOffsetName = m_OutBuff.GetOffset() - dwStartInfoOffset;
  460. m_OutBuff.WriteBSTR(bstr);
  461. }
  462. if(pvar->vt != VT_EMPTY && pvar->vt != VT_NULL)
  463. {
  464. CMoValue& Value = pQual->AccessValue();
  465. qu.dwOffsetValue = m_OutBuff.GetOffset() - dwStartInfoOffset;
  466. AddVariant(pvar, &Value);
  467. qu.dwType = pvar->vt;
  468. }
  469. qu.dwLength = m_OutBuff.GetOffset() - dwStartingOffset;
  470. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&qu,
  471. sizeof(WBEM_Qualifier));
  472. return 0;
  473. }
  474. //***************************************************************************
  475. //
  476. // DWORD CBMOFOut::AddVariant
  477. //
  478. // DESCRIPTION:
  479. //
  480. // Adds a value to the BMOF buffer.
  481. //
  482. // PARAMETERS:
  483. //
  484. // pvar value to add.
  485. //
  486. // RETURN VALUE:
  487. //
  488. // Total bytes written
  489. //
  490. //***************************************************************************
  491. DWORD CBMOFOut::AddVariant(VARIANT * pvar, CMoValue * pValue)
  492. {
  493. if(pValue && pValue->GetNumAliases() > 0)
  494. pvar->vt |= VT_BYREF;
  495. VARTYPE vtSimple = pvar->vt & ~VT_ARRAY & ~VT_BYREF;
  496. if(pvar->vt & VT_ARRAY)
  497. {
  498. DWORD dwStartingOffset = m_OutBuff.GetOffset();
  499. DWORD dwSize = 0;
  500. m_OutBuff.AppendBytes((BYTE *)&dwSize, sizeof(DWORD));
  501. DWORD dwTotal = 0;
  502. SCODE sc;
  503. SAFEARRAY * psa;
  504. long ix[2] = {0,0};
  505. long uLower, uUpper;
  506. psa = pvar->parray;
  507. sc = SafeArrayGetLBound(psa,1,&uLower);
  508. sc |= SafeArrayGetUBound(psa,1,&uUpper);
  509. if(sc != S_OK)
  510. return 0;
  511. // write the number of dimensions and the size of each
  512. DWORD dwNumDim = 1; // for now!!!
  513. m_OutBuff.AppendBytes((BYTE *)&dwNumDim, sizeof(long)); // Number of dimensions
  514. DWORD dwNumElem = uUpper - uLower + 1;
  515. m_OutBuff.AppendBytes((BYTE *)&dwNumElem, sizeof(long));
  516. // Write out the row size
  517. DWORD dwStartingRowOffset = m_OutBuff.GetOffset();
  518. DWORD dwRowSize = 0;
  519. m_OutBuff.AppendBytes((BYTE *)&dwRowSize, sizeof(DWORD));
  520. // Get each element and write it
  521. for(ix[0] = uLower; ix[0] <= uUpper && sc == S_OK; ix[0]++)
  522. {
  523. VARIANT var;
  524. VariantInit(&var);
  525. var.vt = vtSimple;
  526. sc = SafeArrayGetElement(psa,ix,&var.bstrVal);
  527. if(sc != S_OK)
  528. {
  529. Trace(true, m_pDbg, SAFE_ARRAY_ERROR);
  530. }
  531. if(ix[0] < uUpper)
  532. m_OutBuff.SetPadMode(FALSE);
  533. else
  534. m_OutBuff.SetPadMode(TRUE);
  535. dwTotal += AddSimpleVariant(&var, ix[0], pValue);
  536. if(var.vt != VT_EMBEDDED_OBJECT) // Our dispatch is actual a CMObject *
  537. VariantClear(&var);
  538. }
  539. // Update the size of the property and the row. Note that having a separate size
  540. // is for possible future support of multi dimensional arrays.
  541. dwRowSize = m_OutBuff.GetOffset() - dwStartingRowOffset;
  542. m_OutBuff.WriteBytes(dwStartingRowOffset, (BYTE *)&dwRowSize,
  543. sizeof(DWORD));
  544. dwSize = m_OutBuff.GetOffset() - dwStartingOffset;
  545. m_OutBuff.WriteBytes(dwStartingOffset, (BYTE *)&dwSize,
  546. sizeof(DWORD));
  547. return dwTotal;
  548. }
  549. else
  550. return AddSimpleVariant(pvar, -1, pValue);
  551. }
  552. //***************************************************************************
  553. //
  554. // DWORD CBMOFOut::AddSimpleVariant
  555. //
  556. // DESCRIPTION:
  557. //
  558. // Adds a non array variant to the BMOF buffer.
  559. //
  560. // PARAMETERS:
  561. //
  562. // pvar value to add.
  563. // iIndex set to -1 if property in scalar, or if array, has
  564. // the index of this element. Note that arrays are
  565. // broken up into simple variants.
  566. //
  567. //
  568. // RETURN VALUE:
  569. //
  570. // Bytes written
  571. //***************************************************************************
  572. DWORD CBMOFOut::AddSimpleVariant(VARIANT * pvar, int iIndex, CMoValue * pValue)
  573. {
  574. DWORD dwSize = iTypeSize(pvar->vt & ~VT_BYREF);
  575. VARTYPE vtSimple = pvar->vt & ~VT_BYREF;
  576. if(pValue && pValue->GetNumAliases() && (vtSimple == VT_BSTR))
  577. {
  578. WCHAR * wszAlias = NULL;
  579. int iTry, iAlIndex = -1;
  580. if(iIndex == -1)
  581. pValue->GetAlias(0, wszAlias, iAlIndex);
  582. else
  583. {
  584. for(iTry = 0; iTry < pValue->GetNumAliases(); iTry++)
  585. {
  586. pValue->GetAlias(iTry, wszAlias, iAlIndex);
  587. if(iIndex == iAlIndex)
  588. break;
  589. }
  590. if(iTry == pValue->GetNumAliases())
  591. wszAlias = NULL;
  592. }
  593. if(wszAlias && iIndex == -1)
  594. pvar->bstrVal = SysAllocString(wszAlias);
  595. else if(wszAlias && iIndex != -1)
  596. {
  597. DWORD dwLen = wcslen(wszAlias)+2;
  598. WCHAR * pTemp = new WCHAR[dwLen];
  599. if(pTemp == NULL)
  600. return 0;
  601. pTemp[0]= L'$';
  602. StringCchCopyW(pTemp+1, dwLen-1, wszAlias);
  603. pvar->bstrVal = SysAllocString(pTemp);
  604. delete pTemp;
  605. }
  606. else if(wszAlias == NULL && iIndex != -1)
  607. {
  608. DWORD dwLen = wcslen(pvar->bstrVal)+2;
  609. WCHAR * pTemp = new WCHAR[dwLen];
  610. if(pTemp == NULL)
  611. return 0;
  612. pTemp[0]= L' ';
  613. StringCchCopyW(pTemp+1, dwLen-1, pvar->bstrVal);
  614. pvar->bstrVal = SysAllocString(pTemp);
  615. delete pTemp;
  616. }
  617. }
  618. if(vtSimple == VT_BSTR)
  619. return m_OutBuff.WriteBSTR(pvar->bstrVal);
  620. else if(vtSimple == VT_EMBEDDED_OBJECT)
  621. {
  622. CMObject * pObj = (CMObject *)pvar->punkVal;
  623. return AddClass(pObj, TRUE);
  624. }
  625. else
  626. return m_OutBuff.AppendBytes((BYTE *)&pvar->bstrVal, dwSize);
  627. }
  628. //***************************************************************************
  629. //
  630. // BOOL CBMOFOut::WriteFile
  631. //
  632. // DESCRIPTION:
  633. //
  634. // Writes the buffer out to the file.
  635. //
  636. //***************************************************************************
  637. BOOL CBMOFOut::WriteFile()
  638. {
  639. BOOL bRet = FALSE;
  640. if(m_pFile)
  641. {
  642. m_BinMof.dwLength = m_OutBuff.GetOffset();
  643. m_OutBuff.WriteBytes(0, (BYTE *)&m_BinMof, sizeof(WBEM_Binary_MOF));
  644. #ifdef UNICODE
  645. char cFile[MAX_PATH];
  646. wcstombs(cFile, m_pFile, MAX_PATH);
  647. bRet = m_OutBuff.WriteToFile(cFile);
  648. #else
  649. bRet = m_OutBuff.WriteToFile(m_pFile);
  650. #endif
  651. }
  652. return bRet;
  653. }