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.

155 lines
4.1 KiB

  1. #include <fusenetincludes.h>
  2. #include <applicationinfo.h>
  3. // ---------------------------------------------------------------------------
  4. // CreateManifestApplicationInfo
  5. // ---------------------------------------------------------------------------
  6. STDAPI
  7. CreateManifestApplicationInfo(
  8. LPMANIFEST_APPLICATION_INFO* ppManifestApplicationInfo)
  9. {
  10. HRESULT hr = S_OK;
  11. LPMANIFEST_APPLICATION_INFO pManifestApplicationInfo = NULL;
  12. if (ppManifestApplicationInfo == NULL)
  13. {
  14. hr = E_INVALIDARG;
  15. goto exit;
  16. }
  17. *ppManifestApplicationInfo = NULL;
  18. pManifestApplicationInfo = new(CManifestApplicationInfo);
  19. if (!pManifestApplicationInfo)
  20. {
  21. hr = E_OUTOFMEMORY;
  22. goto exit;
  23. }
  24. *ppManifestApplicationInfo = static_cast<IManifestApplicationInfo*> (pManifestApplicationInfo);
  25. exit:
  26. return hr;
  27. }
  28. // ---------------------------------------------------------------------------
  29. // ctor
  30. // ---------------------------------------------------------------------------
  31. CManifestApplicationInfo::CManifestApplicationInfo()
  32. : _dwSig('OFIA'), _cRef(1), _hr(S_OK)
  33. {
  34. memset(_ai, 0, sizeof(_ai));
  35. }
  36. // ---------------------------------------------------------------------------
  37. // dtor
  38. // ---------------------------------------------------------------------------
  39. CManifestApplicationInfo::~CManifestApplicationInfo()
  40. {
  41. for (DWORD i = MAN_APPLICATION_FRIENDLYNAME; i < MAN_APPLICATION_MAX; i++)
  42. SAFEDELETEARRAY(_ai[i].pwzProperty);
  43. }
  44. // ---------------------------------------------------------------------------
  45. // Set
  46. // ---------------------------------------------------------------------------
  47. HRESULT CManifestApplicationInfo::Set(DWORD dwId, LPCOLESTR pwzProperty)
  48. {
  49. DWORD ccProperty = lstrlen(pwzProperty) + 1;
  50. LPWSTR pwzTmp = NULL;
  51. if (pwzProperty != NULL)
  52. {
  53. pwzTmp = new WCHAR[ccProperty];
  54. if (!pwzTmp)
  55. {
  56. _hr = E_OUTOFMEMORY;
  57. goto exit;
  58. }
  59. memcpy(pwzTmp, pwzProperty, ccProperty * sizeof(WCHAR));
  60. }
  61. else
  62. ccProperty = 0;
  63. SAFEDELETEARRAY(_ai[dwId].pwzProperty);
  64. _ai[dwId].pwzProperty = pwzTmp;
  65. _ai[dwId].ccProperty = ccProperty;
  66. exit:
  67. return _hr;
  68. }
  69. // ---------------------------------------------------------------------------
  70. // Get
  71. // ---------------------------------------------------------------------------
  72. HRESULT CManifestApplicationInfo::Get(DWORD dwId, LPOLESTR *ppwzProperty, LPDWORD pccProperty)
  73. {
  74. *ppwzProperty = NULL;
  75. *pccProperty = 0;
  76. DWORD ccProperty = _ai[dwId].ccProperty;
  77. LPWSTR pwzProperty = NULL;
  78. if (_ai[dwId].pwzProperty == NULL)
  79. goto exit;
  80. pwzProperty = new WCHAR[ccProperty];
  81. if (!pwzProperty)
  82. {
  83. _hr = E_OUTOFMEMORY;
  84. goto exit;
  85. }
  86. memcpy(pwzProperty, _ai[dwId].pwzProperty, ccProperty * sizeof(WCHAR));
  87. *ppwzProperty = pwzProperty;
  88. *pccProperty = ccProperty;
  89. exit:
  90. return _hr;
  91. }
  92. // IUnknown Boilerplate
  93. // ---------------------------------------------------------------------------
  94. // CManifestApplicationInfo::QI
  95. // ---------------------------------------------------------------------------
  96. STDMETHODIMP
  97. CManifestApplicationInfo::QueryInterface(REFIID riid, void** ppvObj)
  98. {
  99. if ( IsEqualIID(riid, IID_IUnknown)
  100. || IsEqualIID(riid, IID_IManifestApplicationInfo)
  101. )
  102. {
  103. *ppvObj = static_cast<IManifestApplicationInfo*> (this);
  104. AddRef();
  105. return S_OK;
  106. }
  107. else
  108. {
  109. *ppvObj = NULL;
  110. return E_NOINTERFACE;
  111. }
  112. }
  113. // ---------------------------------------------------------------------------
  114. // CManifestApplicationInfo::AddRef
  115. // ---------------------------------------------------------------------------
  116. STDMETHODIMP_(ULONG)
  117. CManifestApplicationInfo::AddRef()
  118. {
  119. return InterlockedIncrement ((LONG*) &_cRef);
  120. }
  121. // ---------------------------------------------------------------------------
  122. // CManifestApplicationInfo::Release
  123. // ---------------------------------------------------------------------------
  124. STDMETHODIMP_(ULONG)
  125. CManifestApplicationInfo::Release()
  126. {
  127. ULONG lRet = InterlockedDecrement ((LONG*) &_cRef);
  128. if (!lRet)
  129. delete this;
  130. return lRet;
  131. }