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.

116 lines
2.7 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. METADATA.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "metadata.h"
  9. #include <stdio.h>
  10. HMM_CLASS_RELATION CMetaData::GetClassRelation(LPCWSTR wszClass1,
  11. LPCWSTR wszClass2)
  12. {
  13. char ch;
  14. printf("Is %S derived from %S? ", wszClass1, wszClass2);
  15. scanf("%c%*c", &ch);
  16. if(ch == 'y' || ch == 'Y')
  17. return SECOND_IS_PARENT;
  18. printf("Is %S derived from %S? ", wszClass2, wszClass1);
  19. scanf("%c%*c", &ch);
  20. if(ch == 'y' || ch == 'Y')
  21. return FIRST_IS_PARENT;
  22. else
  23. return SEPARATE_BRANCHES;
  24. }
  25. RELEASE_ME IHmmClassObject* CMetaData::ConvertSource(
  26. IHmmPropertySource* pSource,
  27. IHmmPropertyList* pList = NULL)
  28. {
  29. HRESULT hres;
  30. VARIANT v;
  31. VariantInit(&v);
  32. // Get the class
  33. // =============
  34. if(FAILED(pSource->GetPropertyValue(L"__CLASS", 0, &v)))
  35. return NULL;
  36. if(V_VT(&v) != VT_BSTR)
  37. {
  38. VariantClear(&v);
  39. return NULL;
  40. }
  41. IHmmClassObject* pClass;
  42. hres = m_pNamespace->GetObject(V_BSTR(&v), 0, &pClass, NULL);
  43. VariantClear(&v);
  44. if(FAILED(hres))
  45. return NULL;
  46. // Spawn an instance
  47. // =================
  48. IHmmClassObject* pInstance;
  49. pClass->SpawnInstance(0, &pInstance);
  50. pClass->Release();
  51. // Either enumerate all properties in the list, or in the class
  52. // ============================================================
  53. if(pList != NULL)
  54. {
  55. long lNumProps;
  56. HMM_WSTR* aProps;
  57. pList->GetList(0, &lNumProps, &aProps);
  58. for(long l = 0; l < lNumProps; l++)
  59. {
  60. if(SUCCEEDED(pSource->PropertyValue(aProps[l], 0, &v)))
  61. {
  62. if(FAILED(pInstance->Put(aProps[l], 0, &v, 0)))
  63. {
  64. // requested property not in the class. So what.
  65. }
  66. }
  67. else
  68. {
  69. // requested property not available. So what.
  70. }
  71. VariantClear(&v);
  72. }
  73. }
  74. else
  75. {
  76. pInstance->BeginEnumeration(HMM_FLAG_NONSYSTEM_ONLY);
  77. BSTR strName;
  78. while(pInstance->Next(&strName, NULL, NULL, NULL))
  79. {
  80. if(SUCCEEDED(pSource->PropertyValue(strName, 0, &v)))
  81. {
  82. if(FAILED(pInstance->Put(strName, 0, &v, 0)))
  83. {
  84. // requested property not in the class. So what.
  85. }
  86. }
  87. else
  88. {
  89. // requested property not available. So what.
  90. }
  91. VariantClear(&v);
  92. }
  93. }
  94. return pInstance;
  95. }