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.

792 lines
21 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. BMOFHELP.CPP
  5. Abstract:
  6. Creates the object list from the binary mof file
  7. History:
  8. a-davj 14-April-97 Created.
  9. --*/
  10. #include "precomp.h"
  11. #include <stdio.h>
  12. #include <float.h>
  13. #include <mofout.h>
  14. #include <mofparse.h>
  15. #include <moflex.h>
  16. #include <mofdata.h>
  17. #include <typehelp.h>
  18. #include <io.h>
  19. #include <fcntl.h>
  20. #include <stdio.h>
  21. #include <sys/stat.h>
  22. //#include <corepol.h>
  23. #include <wbemutil.h>
  24. #include <genutils.h>
  25. #include "bmof.h"
  26. #include "cbmofout.h"
  27. #include "bmofhelp.h"
  28. #include "trace.h"
  29. #include "strings.h"
  30. #include "mrcicode.h"
  31. #include <autoptr.h>
  32. #include <arrtempl.h>
  33. long lObjectNumber = 0;
  34. class CFreeMe
  35. {
  36. private:
  37. VARIANT * m_pVar;
  38. public:
  39. CFreeMe(VARIANT * pVar){m_pVar = pVar;};
  40. ~CFreeMe();
  41. };
  42. CFreeMe::~CFreeMe()
  43. {
  44. if(m_pVar)
  45. {
  46. VARTYPE vt = m_pVar->vt & ~VT_ARRAY;
  47. try
  48. {
  49. if(vt == VT_BSTR)
  50. VariantClear(m_pVar);
  51. else if(m_pVar->vt & VT_ARRAY)
  52. SafeArrayDestroyDescriptor(m_pVar->parray);
  53. m_pVar->vt = VT_EMPTY;
  54. }
  55. catch(...)
  56. {}
  57. }
  58. }
  59. //***************************************************************************
  60. //
  61. // CMoQualifierArray * CreateQual
  62. //
  63. // DESCRIPTION:
  64. //
  65. // Creates a CMoQualifierArray by using a CBMOFQualList object.
  66. //
  67. // RETURN VALUE:
  68. //
  69. // Pointer to new object, NULL if error.
  70. //
  71. //***************************************************************************
  72. CMoQualifierArray * CreateQual(CMofData * pOutput, CBMOFQualList * pql, CMObject * pObj,LPCWSTR wszPropName, PDBG pDbg)
  73. {
  74. ResetQualList(pql);
  75. WCHAR * pName = NULL;
  76. DWORD dwFlavor= 0;
  77. CBMOFDataItem Data;
  78. VARIANT var;
  79. VariantInit(&var);
  80. CMoQualifierArray * pRet = new CMoQualifierArray(pDbg);
  81. if(pRet == NULL)
  82. return NULL;
  83. while(NextQualEx(pql, &pName, &Data, &dwFlavor, pOutput->GetBmofBuff(), pOutput->GetBmofToFar()))
  84. {
  85. BOOL bAliasRef;
  86. VariantInit(&var);
  87. BMOFToVariant(pOutput, &Data, &var, bAliasRef,FALSE, pDbg);
  88. CFreeMe fm(&var);
  89. wmilib::auto_ptr<CMoQualifier> pQual(new CMoQualifier(pDbg));
  90. if(pQual.get() == NULL)
  91. return NULL;
  92. if(pName == NULL || FAILED(pQual->SetQualName(pName)))
  93. return NULL;
  94. if(dwFlavor)
  95. {
  96. if(dwFlavor & WBEM_FLAVOR_AMENDED)
  97. {
  98. pQual->SetAmended(true);
  99. }
  100. else
  101. pQual->SetAmended(false);
  102. pQual->SetFlavor(dwFlavor);
  103. }
  104. BOOL bArray = var.vt & VT_ARRAY;
  105. if(bAliasRef && !bArray)
  106. {
  107. CMoValue & Value = pQual->AccessValue();
  108. if(FAILED(AddAliasReplaceValue(Value, var.bstrVal)))
  109. return NULL;
  110. }
  111. else if(bAliasRef && bArray)
  112. {
  113. SAFEARRAY* psaSrc = var.parray;
  114. long lLBound, lUBound;
  115. SafeArrayGetLBound(psaSrc, 1, &lLBound);
  116. SafeArrayGetUBound(psaSrc, 1, &lUBound);
  117. CMoValue & Value = pQual->AccessValue();
  118. for(long lIndex = lLBound; lIndex <= lUBound; lIndex++)
  119. {
  120. // Load the initial data element into a VARIANT
  121. // ============================================
  122. BSTR bstr;
  123. SCODE sc = SafeArrayGetElement(psaSrc, &lIndex, &bstr);
  124. if(FAILED(sc))
  125. return NULL;
  126. CSysFreeMe FM(bstr);
  127. if(bstr[0] == L'$')
  128. {
  129. sc = Value.AddAlias(&bstr[1], lIndex); // skip the leading $
  130. if(FAILED(sc))
  131. return NULL;
  132. GUID guid;
  133. CoCreateGuid(&guid);
  134. WCHAR wszGuidBuffer[100];
  135. StringFromGUID2(guid, wszGuidBuffer, 100);
  136. BSTR bstrNew = SysAllocString(wszGuidBuffer);
  137. if(bstrNew == NULL)
  138. return NULL;
  139. sc = SafeArrayPutElement(psaSrc, &lIndex, bstrNew);
  140. SysFreeString(bstrNew);
  141. if(FAILED(sc))
  142. return NULL;
  143. }
  144. }
  145. SCODE sc = WbemVariantChangeType(pQual->GetpVar(), &var, var.vt);
  146. }
  147. else
  148. {
  149. SCODE sc = WbemVariantChangeType(pQual->GetpVar(), &var, var.vt);
  150. }
  151. // VariantClear(&var);
  152. free(pName);
  153. if (pRet->Add(pQual.get()))
  154. {
  155. pQual.release();
  156. }
  157. }
  158. pRet->RegisterAliases(pObj,wszPropName);
  159. return pRet;
  160. }
  161. //***************************************************************************
  162. //
  163. // SCODE ConvertValue
  164. //
  165. // DESCRIPTION:
  166. //
  167. // Creates a CMoQualifierArray by using a CBMOFQualList object.
  168. //
  169. // RETURN VALUE:
  170. //
  171. // Pointer to new object, NULL if error.
  172. //
  173. //***************************************************************************
  174. SCODE ConvertValue(CMoProperty * pProp, VARIANT * pSrc, BOOL bAliasRef)
  175. {
  176. VARIANT * pDest;
  177. pDest = pProp->GetpVar();
  178. if((pSrc->vt & ~VT_ARRAY) == VT_EMBEDDED_OBJECT)
  179. {
  180. pDest->vt = pSrc->vt;
  181. pDest->punkVal = pSrc->punkVal; // also works if this is parrayVal!
  182. pSrc->vt = VT_EMPTY; // DONT CLEAR THIS since destination is taking ownership
  183. return S_OK;
  184. }
  185. if(!bAliasRef)
  186. return WbemVariantChangeType(pProp->GetpVar(), pSrc, pSrc->vt);
  187. if(pSrc->vt == VT_BSTR)
  188. {
  189. CMoValue & Value = pProp->AccessValue();
  190. return AddAliasReplaceValue(Value, pSrc->bstrVal);
  191. }
  192. if(pSrc->vt == (VT_BSTR | VT_ARRAY))
  193. {
  194. SAFEARRAY* psaSrc = V_ARRAY(pSrc);
  195. long lLBound, lUBound;
  196. SafeArrayGetLBound(psaSrc, 1, &lLBound);
  197. SafeArrayGetUBound(psaSrc, 1, &lUBound);
  198. // Stuff the individual data pieces
  199. // ================================
  200. for(long lIndex = lLBound; lIndex <= lUBound; lIndex++)
  201. {
  202. // Load the initial data element into a VARIANT
  203. // ============================================
  204. BSTR bstr;
  205. SafeArrayGetElement(psaSrc, &lIndex, &bstr);
  206. if(bstr[0] == L' ')
  207. {
  208. BSTR bstrNew = SysAllocString(&bstr[1]);
  209. if(bstrNew == NULL)
  210. return WBEM_E_OUT_OF_MEMORY;
  211. SCODE sc2 = SafeArrayPutElement(psaSrc, &lIndex, bstrNew);
  212. SysFreeString(bstrNew);
  213. if(FAILED(sc2))
  214. return sc2;
  215. }
  216. else
  217. {
  218. CMoValue & Value = pProp->AccessValue();
  219. HRESULT hr2 = Value.AddAlias(&bstr[1],lIndex); // skip over the $ used it indcate alias
  220. if(FAILED(hr2))
  221. return hr2;
  222. // Create a unique value and put it in there
  223. // =========================================
  224. GUID guid;
  225. CoCreateGuid(&guid);
  226. WCHAR wszGuidBuffer[100];
  227. StringFromGUID2(guid, wszGuidBuffer, 100);
  228. BSTR bstrNew = SysAllocString(wszGuidBuffer);
  229. if(bstrNew == NULL)
  230. return WBEM_E_OUT_OF_MEMORY;
  231. SCODE sc2 = SafeArrayPutElement(psaSrc, &lIndex, bstrNew);
  232. SysFreeString(bstrNew);
  233. if(FAILED(sc2))
  234. return sc2;
  235. }
  236. }
  237. return WbemVariantChangeType(pProp->GetpVar(), pSrc, pSrc->vt);
  238. }
  239. else
  240. return WBEM_E_FAILED;
  241. }
  242. //***************************************************************************
  243. //
  244. // BOOL ConvertBufferIntoIntermediateForm()
  245. //
  246. // DESCRIPTION:
  247. //
  248. // Creates a CMObject (the parse object format) from a CBMOFObj (binary mof format)
  249. // object.
  250. //
  251. // PARAMETERS:
  252. //
  253. // pOutput Pointer to object that will hold the intermediate data.
  254. // pBuff Binary mof data.
  255. //
  256. // RETURN VALUE:
  257. //
  258. // TRUE if OK.
  259. //
  260. //***************************************************************************
  261. BOOL ConvertBufferIntoIntermediateForm(CMofData * pOutput, BYTE * pBuff, PDBG pDbg, BYTE * pBmofToFar)
  262. {
  263. CBMOFObj * po;
  264. BOOL bRet;
  265. // Create a ObjList object
  266. pOutput->SetBmofBuff(pBuff);
  267. pOutput->SetBmofToFar(pBmofToFar);
  268. CBMOFObjList * pol = CreateObjList(pBuff);
  269. ResetObjList(pol);
  270. OnDelete<void *,void(__cdecl *)(void *),free> fm(pol);
  271. lObjectNumber = 0;
  272. while(po = NextObj(pol))
  273. {
  274. if(!BMOFParseObj(pOutput, po, NULL, FALSE, pDbg))
  275. {
  276. free(po);
  277. return FALSE;
  278. }
  279. free(po);
  280. lObjectNumber++;
  281. }
  282. bRet = TRUE; // Got all the way through with no errors.
  283. return bRet;
  284. }
  285. //***************************************************************************
  286. //
  287. // BOOL BMOFParseObj
  288. //
  289. // DESCRIPTION:
  290. //
  291. // Creates a CMObject (the parse object format) from a CBMOFObj (binary mof format)
  292. // object.
  293. //
  294. // PARAMETERS:
  295. //
  296. // pObj pointer to binary mof object.
  297. // pVar poninter to a variant which will point to the resulting
  298. // object. If this is NULL, then the object is a top level
  299. // (not embedded) object and it will be added to the main
  300. // object list.
  301. //
  302. // RETURN VALUE:
  303. //
  304. // TRUE if OK.
  305. //
  306. //***************************************************************************
  307. BOOL BMOFParseObj(CMofData * pOutput, CBMOFObj * po, VARIANT * pVar, BOOL bMethArg, PDBG pDbg)
  308. {
  309. VARIANT var;
  310. CBMOFDataItem Data;
  311. WCHAR * pClassName;
  312. BOOL bAliasRef;
  313. CMoQualifierArray * paQualifiers;
  314. wmilib::auto_ptr<CMObject> pObject;
  315. // Check the type. This is a sanity check for weeding out old format files!
  316. DWORD dwType = GetType(po);
  317. if(dwType != 0 && dwType != 1)
  318. {
  319. Trace(true,pDbg,INVALID_BMOF_OBJECT_TYPE);
  320. return FALSE;
  321. }
  322. // Create either the new class of instance object
  323. if(!GetName(po, &pClassName))
  324. {
  325. Trace(true,pDbg, CANT_FIND_CLASS_NAME);
  326. return FALSE;
  327. }
  328. if(GetType(po) == 0)
  329. {
  330. if(FindProp(po, L"__SuperClass", &Data))
  331. {
  332. BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  333. pObject.reset(new CMoClass( var.bstrVal, pClassName, pDbg));
  334. VariantClear(&var);
  335. }
  336. else
  337. pObject.reset(new CMoClass( NULL, pClassName, pDbg));
  338. }
  339. else
  340. {
  341. pObject.reset(new CMoInstance(pClassName, pDbg));
  342. }
  343. free(pClassName);
  344. if(pObject.get() == NULL)
  345. return FALSE;
  346. if(pObject->IsOK() == false)
  347. return FALSE;
  348. // Get the namespace and add it
  349. if(FindProp(po, L"__Namespace", &Data))
  350. {
  351. BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  352. HRESULT hr = pObject->SetNamespace(var.bstrVal);
  353. VariantClear(&var);
  354. if(FAILED(hr))
  355. return FALSE;
  356. }
  357. // Add other pragma values
  358. long lClass = 0;
  359. long lInstance = 0;
  360. if(FindProp(po, L"__ClassFlags", &Data))
  361. {
  362. BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  363. lClass = var.lVal;
  364. VariantClear(&var);
  365. }
  366. if(FindProp(po, L"__InstanceFlags", &Data))
  367. {
  368. BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  369. lInstance = var.lVal;
  370. VariantClear(&var);
  371. }
  372. pObject->SetOtherDefaults(lClass, lInstance);
  373. if(FindProp(po, L"__ALIAS", &Data))
  374. {
  375. BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  376. HRESULT hr2 = pObject->SetAlias(var.bstrVal);
  377. VariantClear(&var);
  378. if(FAILED(hr2))
  379. {
  380. return FALSE;
  381. }
  382. }
  383. CBMOFQualList * pql = GetQualList(po);
  384. if(pql)
  385. {
  386. paQualifiers = CreateQual(pOutput, pql, pObject.get(), NULL, pDbg);
  387. if(paQualifiers)
  388. pObject->SetQualifiers(paQualifiers);
  389. free(pql);
  390. }
  391. ResetObj(po);
  392. WCHAR * pPropName = NULL;
  393. while(NextProp(po, &pPropName, &Data))
  394. {
  395. VariantInit(&var);
  396. BOOL bGotValue = BMOFToVariant(pOutput, &Data, &var, bAliasRef, FALSE, pDbg);
  397. CFreeMe fm(&var);
  398. // ignore these special properties
  399. if(!wbem_wcsicmp(pPropName,L"__Class") ||
  400. !wbem_wcsicmp(pPropName,L"__SuperClass") ||
  401. !wbem_wcsicmp(pPropName,L"__ALIAS") ||
  402. !wbem_wcsicmp(pPropName,L"__CLASSFLAGS") ||
  403. !wbem_wcsicmp(pPropName,L"__INSTANCEFLAGS") ||
  404. !wbem_wcsicmp(pPropName,L"__NameSpace"))
  405. {
  406. free(pPropName);
  407. continue;
  408. }
  409. wmilib::auto_ptr<CValueProperty> pProp( new CValueProperty(NULL, pDbg));
  410. if(pProp.get() == NULL)
  411. return FALSE;
  412. if(FAILED(pProp->SetPropName(pPropName)))
  413. return FALSE;
  414. pql = GetPropQualList(po, pPropName);
  415. paQualifiers = NULL;
  416. if(pql)
  417. {
  418. if(paQualifiers = CreateQual(pOutput, pql, pObject.get(), pPropName, pDbg))
  419. pProp->SetQualifiers(paQualifiers);
  420. free(pql);
  421. if(paQualifiers == NULL)
  422. return FALSE;
  423. }
  424. if(bGotValue)
  425. {
  426. SCODE sc = ConvertValue(pProp.get(), &var, bAliasRef);
  427. }
  428. else
  429. {
  430. VARIANT * t_pVar = pProp->GetpVar();
  431. t_pVar->vt = VT_NULL;
  432. t_pVar->lVal = 0;
  433. }
  434. // Set the type. Note that numeric types are stored as strings and so it is necessary to
  435. // get the type from the cimtype qualifier
  436. CMoValue* pValue = NULL;
  437. if(paQualifiers)
  438. pValue = paQualifiers->Find(L"CIMTYPE");
  439. if(pValue)
  440. {
  441. CMoType Type(pDbg);
  442. VARIANT& varRef = pValue->AccessVariant();
  443. if(varRef.vt == VT_BSTR && varRef.bstrVal)
  444. {
  445. HRESULT hr2 = Type.SetTitle(varRef.bstrVal);
  446. if(FAILED(hr2))
  447. {
  448. return FALSE;
  449. }
  450. VARTYPE vt = Type.GetCIMType();
  451. if(Data.m_dwType & VT_ARRAY)
  452. vt |= VT_ARRAY;
  453. pProp->SetType(vt);
  454. }
  455. }
  456. else
  457. pProp->SetType((VARTYPE)Data.m_dwType);
  458. if (pObject->AddProperty(pProp.get()))
  459. {
  460. pProp->RegisterAliases(pObject.get());
  461. if(bMethArg)
  462. pProp->SetAsArg();
  463. pProp.release();
  464. }
  465. free(pPropName);
  466. pPropName = NULL;
  467. }
  468. // Get the methods
  469. WCHAR * pMethName = NULL;
  470. while(NextMeth(po, &pMethName, &Data))
  471. {
  472. VariantClear(&var);
  473. BOOL bGotValue = BMOFToVariant(pOutput, &Data, &var, bAliasRef, TRUE, pDbg);
  474. CFreeMe fm(&var);
  475. wmilib::auto_ptr<CMethodProperty> pMeth( new CMethodProperty(NULL, pDbg, TRUE));
  476. if(pMeth.get() == NULL)
  477. return FALSE;
  478. if(FAILED(pMeth->SetPropName(pMethName)))
  479. return FALSE;
  480. pql = GetMethQualList(po, pMethName);
  481. paQualifiers = NULL;
  482. if(pql)
  483. {
  484. if(paQualifiers = CreateQual(pOutput, pql, pObject.get(), pMethName, pDbg))
  485. pMeth->SetQualifiers(paQualifiers);
  486. free(pql);
  487. }
  488. if(bGotValue)
  489. {
  490. SCODE sc = ConvertValue(pMeth.get(), &var, bAliasRef);
  491. long lLower, lUpper, lCnt;
  492. sc = SafeArrayGetLBound(var.parray, 1, &lLower);
  493. sc = SafeArrayGetUBound(var.parray, 1, &lUpper);
  494. CMoInstance * pTemp;
  495. for(lCnt = lLower; lCnt <= lUpper; lCnt++)
  496. {
  497. pTemp = NULL;
  498. sc = SafeArrayGetElement(var.parray, &lCnt, &pTemp);
  499. if(sc == S_OK && pTemp)
  500. {
  501. // If there are two objects, then the first is inputs and the second outputs. If there
  502. // is just one, examine the object
  503. if(lLower != lUpper && lCnt == lLower)
  504. pMeth->SetIn(pTemp);
  505. else if(lLower != lUpper && lCnt == lUpper)
  506. pMeth->SetOut(pTemp);
  507. else if(pTemp->IsInput())
  508. pMeth->SetIn(pTemp);
  509. else
  510. pMeth->SetOut(pTemp);
  511. }
  512. }
  513. }
  514. else
  515. {
  516. VARIANT * t_pVar = pMeth->GetpVar();
  517. t_pVar->vt = VT_NULL;
  518. t_pVar->lVal = 0;
  519. }
  520. pMeth->SetType((VARTYPE)Data.m_dwType);
  521. if (pObject->AddProperty(pMeth.get()))
  522. {
  523. pMeth->RegisterAliases(pObject.get());
  524. pMeth.release();
  525. }
  526. free(pMethName);
  527. }
  528. if(pVar)
  529. {
  530. pVar->punkVal = (IUnknown *)pObject.get();
  531. }
  532. else
  533. pOutput->AddObject(pObject.get());
  534. pObject.release();
  535. return TRUE;
  536. }
  537. //***************************************************************************
  538. //
  539. // BOOL BMOFToVariant
  540. //
  541. // DESCRIPTION:
  542. //
  543. // Converts a bmof data object into a variant
  544. //
  545. //***************************************************************************
  546. BOOL BMOFToVariant(CMofData * pOutput, CBMOFDataItem * pData, VARIANT * pVar, BOOL & bAliasRef, BOOL bMethodArg, PDBG pDbg)
  547. {
  548. SCODE sc;
  549. VariantInit(pVar);
  550. DWORD dwSimpleType = pData->m_dwType & ~VT_ARRAY & ~VT_BYREF;
  551. bAliasRef = pData->m_dwType & VT_BYREF;
  552. long lFirstDim;
  553. VARIANT vTemp;
  554. long lNumDim = GetNumDimensions(pData);
  555. if(lNumDim == -1)
  556. return FALSE;
  557. pVar->vt = (WORD)pData->m_dwType & ~VT_BYREF;
  558. if(lNumDim == 0)
  559. {
  560. memset((BYTE *)&(vTemp.lVal),0,8);
  561. if(!GetData(pData, (BYTE *)&(vTemp.lVal), NULL))
  562. {
  563. pVar->vt = VT_EMPTY;
  564. return FALSE;
  565. }
  566. if(dwSimpleType == VT_BSTR)
  567. {
  568. pVar->bstrVal = SysAllocString(vTemp.bstrVal);
  569. BMOFFree(vTemp.bstrVal);
  570. if(pVar->bstrVal == NULL)
  571. return FALSE;
  572. }
  573. else if(dwSimpleType == VT_EMBEDDED_OBJECT)
  574. {
  575. CBMOFObj * pObj;
  576. pObj = (CBMOFObj *)vTemp.bstrVal;
  577. BMOFParseObj(pOutput, pObj, pVar, bMethodArg, pDbg);
  578. BMOFFree(pObj);
  579. return TRUE;
  580. }
  581. else
  582. memcpy((void *)&(pVar->bstrVal), (void *)&(vTemp.bstrVal),8);
  583. return TRUE;
  584. }
  585. lFirstDim = GetNumElements(pData, 0);
  586. DWORD ulLower, ulUpper;
  587. SAFEARRAY * psa;
  588. SAFEARRAYBOUND rgsabound[1];
  589. long ix[2] = {0,0};
  590. ulLower = 0;
  591. ulUpper = lFirstDim-1;
  592. rgsabound[0].lLbound = ulLower;
  593. rgsabound[0].cElements = ulUpper - ulLower +1;
  594. #ifdef _WIN64
  595. VARTYPE vtTemp = (dwSimpleType == VT_EMBEDDED_OBJECT) ? VT_R8 : (VARTYPE)dwSimpleType;
  596. #else
  597. VARTYPE vtTemp = (dwSimpleType == VT_EMBEDDED_OBJECT) ? VT_I4 : (VARTYPE)dwSimpleType;
  598. #endif
  599. psa = SafeArrayCreate(vtTemp,1,rgsabound);
  600. for(ix[0] = ulLower; ix[0] <= (long)ulUpper; ix[0]++)
  601. {
  602. memset((BYTE *)&(vTemp.lVal),0,8);
  603. GetData(pData, (BYTE *)&(vTemp.lVal), ix);
  604. if(dwSimpleType == VT_BSTR)
  605. {
  606. BSTR bstr = SysAllocString(vTemp.bstrVal);
  607. free(vTemp.bstrVal);
  608. vTemp.vt = VT_EMPTY;
  609. if(bstr == NULL)
  610. {
  611. pVar->vt = VT_EMPTY;
  612. return FALSE;
  613. }
  614. sc = SafeArrayPutElement(psa,ix,(void *)bstr);
  615. SysFreeString(bstr);
  616. if(FAILED(sc))
  617. return FALSE;
  618. }
  619. else if(dwSimpleType == VT_EMBEDDED_OBJECT)
  620. {
  621. CBMOFObj * pObj;
  622. VARIANT vConv;
  623. VariantInit(&vConv);
  624. pObj = (CBMOFObj *)vTemp.punkVal;
  625. BMOFParseObj(pOutput, pObj, &vConv, bMethodArg, pDbg);
  626. free(pObj);
  627. sc = SafeArrayPutElement(psa,ix,(void *)&vConv.lVal);
  628. if(FAILED(sc))
  629. return FALSE;
  630. }
  631. else
  632. {
  633. memcpy((void *)&(pVar->bstrVal), (void *)&(vTemp.bstrVal),8);
  634. sc = SafeArrayPutElement(psa,ix,(void *)&(vTemp.lVal));
  635. if(FAILED(sc))
  636. return FALSE;
  637. }
  638. // VariantClear(&vTemp);
  639. }
  640. pVar->parray = psa;
  641. return TRUE;
  642. }
  643. //***************************************************************************
  644. //
  645. // void AddAliasReplaceValue
  646. //
  647. // DESCRIPTION:
  648. //
  649. // Used when a Value has an alias.
  650. //
  651. // RETURN VALUE:
  652. //
  653. // TRUE if the file is a binary mof
  654. //
  655. //***************************************************************************
  656. HRESULT AddAliasReplaceValue(CMoValue & Value, const WCHAR * pAlias)
  657. {
  658. HRESULT hr = Value.AddAlias(pAlias);
  659. if(FAILED(hr))
  660. return hr;
  661. V_VT(&Value.AccessVariant()) = VT_BSTR;
  662. // Create a unique value and put it in there
  663. // =========================================
  664. GUID guid;
  665. CoCreateGuid(&guid);
  666. WCHAR wszGuidBuffer[100];
  667. StringFromGUID2(guid, wszGuidBuffer, 100);
  668. BSTR bstr = SysAllocString(wszGuidBuffer);
  669. if(bstr == NULL)
  670. return WBEM_E_OUT_OF_MEMORY;
  671. V_BSTR(&Value.AccessVariant()) = bstr;
  672. return S_OK;
  673. }
  674. extern "C" void * BMOFAlloc(size_t Size)
  675. {
  676. return malloc(Size);
  677. }
  678. extern "C" void BMOFFree(void * pFree)
  679. {
  680. free(pFree);
  681. }