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.

223 lines
3.7 KiB

  1. /*++
  2. Copyright (C) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. about.cpp
  5. Abstract:
  6. This module implemets ISnapinAbout inteface(CDevMgrAbout class).
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #include "devmgr.h"
  12. #include "about.h"
  13. //
  14. // IUnknown interface
  15. //
  16. ULONG
  17. CDevMgrAbout::AddRef()
  18. {
  19. ::InterlockedIncrement((LONG*)&m_Ref);
  20. return m_Ref;
  21. }
  22. ULONG
  23. CDevMgrAbout::Release()
  24. {
  25. ::InterlockedDecrement((LONG*)&m_Ref);
  26. if (!m_Ref)
  27. {
  28. delete this;
  29. return 0;
  30. }
  31. return m_Ref;
  32. }
  33. STDMETHODIMP
  34. CDevMgrAbout::QueryInterface(
  35. REFIID riid,
  36. void** ppv
  37. )
  38. {
  39. if (!ppv)
  40. {
  41. return E_INVALIDARG;
  42. }
  43. HRESULT hr = S_OK;
  44. if (IsEqualIID(riid, IID_IUnknown))
  45. {
  46. *ppv = (IUnknown*)this;
  47. }
  48. else if (IsEqualIID(riid, IID_ISnapinAbout))
  49. {
  50. *ppv = (ISnapinAbout*)this;
  51. }
  52. else
  53. {
  54. *ppv = NULL;
  55. hr = E_NOINTERFACE;
  56. }
  57. if (SUCCEEDED(hr))
  58. {
  59. AddRef();
  60. }
  61. return hr;
  62. }
  63. // ISnapinAbout interface
  64. STDMETHODIMP
  65. CDevMgrAbout::GetSnapinDescription(
  66. LPOLESTR *ppDescription
  67. )
  68. {
  69. return LoadResourceOleString(IDS_PROGRAM_ABOUT, ppDescription);
  70. }
  71. STDMETHODIMP
  72. CDevMgrAbout::GetProvider(
  73. LPOLESTR *ppProvider
  74. )
  75. {
  76. return LoadResourceOleString(IDS_PROGRAM_PROVIDER, ppProvider);
  77. }
  78. STDMETHODIMP
  79. CDevMgrAbout::GetSnapinVersion(
  80. LPOLESTR *ppVersion
  81. )
  82. {
  83. return LoadResourceOleString(IDS_PROGRAM_VERSION, ppVersion);
  84. }
  85. STDMETHODIMP
  86. CDevMgrAbout::GetSnapinImage(
  87. HICON* phIcon
  88. )
  89. {
  90. if (!phIcon)
  91. {
  92. return E_INVALIDARG;
  93. }
  94. *phIcon = ::LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_DEVMGR));
  95. if (!*phIcon)
  96. {
  97. return E_OUTOFMEMORY;
  98. }
  99. return S_OK;
  100. }
  101. STDMETHODIMP
  102. CDevMgrAbout::GetStaticFolderImage(
  103. HBITMAP* phSmall,
  104. HBITMAP* phSmallOpen,
  105. HBITMAP* phLarge,
  106. COLORREF* pcrMask
  107. )
  108. {
  109. if (!phSmall || !phSmallOpen || !phLarge || !pcrMask)
  110. {
  111. return E_INVALIDARG;
  112. }
  113. *phSmall = ::LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_SYSDM16));
  114. *phSmallOpen = ::LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_SYSDM16));
  115. *phLarge =::LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_SYSDM32));
  116. *pcrMask = RGB(255, 0, 255);
  117. if (NULL == *phSmall || NULL == *phSmallOpen || NULL == *phLarge)
  118. {
  119. if (NULL != *phSmall)
  120. {
  121. ::DeleteObject(*phSmall);
  122. *phSmall = NULL;
  123. }
  124. if (NULL != *phSmallOpen)
  125. {
  126. ::DeleteObject(*phSmallOpen);
  127. *phSmallOpen = NULL;
  128. }
  129. if (NULL != *phLarge)
  130. {
  131. ::DeleteObject(*phLarge);
  132. *phLarge = NULL;
  133. }
  134. return E_OUTOFMEMORY;
  135. }
  136. return S_OK;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // private routine to allocate ole task memory and load the given resource
  140. // string(indicated by its string id) to the allocated memory.
  141. // INPUT:
  142. // StringId -- the string resource id
  143. // LPOLESTR* -- place holder to hold the ole string pointer
  144. // OUTPUT:
  145. // standard OLE HRESULT
  146. HRESULT
  147. CDevMgrAbout::LoadResourceOleString(
  148. int StringId,
  149. LPOLESTR* ppolestr
  150. )
  151. {
  152. if (!ppolestr)
  153. {
  154. return E_INVALIDARG;
  155. }
  156. TCHAR Text[MAX_PATH];
  157. // get the string
  158. ::LoadString(g_hInstance, StringId, Text, ARRAYLEN(Text));
  159. try
  160. {
  161. *ppolestr = AllocOleTaskString(Text);
  162. }
  163. catch (CMemoryException* e)
  164. {
  165. e->Delete();
  166. if (*ppolestr)
  167. {
  168. FreeOleTaskString(*ppolestr);
  169. *ppolestr = NULL;
  170. }
  171. }
  172. if (!*ppolestr)
  173. {
  174. return E_OUTOFMEMORY;
  175. }
  176. return S_OK;
  177. }