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.

219 lines
3.9 KiB

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