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.

401 lines
9.8 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999.
  5. //
  6. // File: about.cxx
  7. //
  8. // Contents: Implementation of ISnapinAbout interface
  9. //
  10. // Classes: CSnapinAbout
  11. //
  12. // History: 2-09-1999 DavidMun Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "headers.hxx"
  16. #pragma hdrstop
  17. #include <ntverp.h> // 602542-2002/04/16-JonN LVER_PRODUCTVERSION_STR
  18. //============================================================================
  19. //
  20. // IUnknown implementation
  21. //
  22. //============================================================================
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Member: CSnapinAbout::QueryInterface
  26. //
  27. // Synopsis: Return the requested interface
  28. //
  29. // History: 02-10-1999 DavidMun Created
  30. //
  31. //----------------------------------------------------------------------------
  32. STDMETHODIMP
  33. CSnapinAbout::QueryInterface(
  34. REFIID riid,
  35. LPVOID *ppvObj)
  36. {
  37. HRESULT hr = S_OK;
  38. // TRACE_METHOD(CSnapinAbout, QueryInterface);
  39. do
  40. {
  41. if (NULL == ppvObj)
  42. {
  43. hr = E_INVALIDARG;
  44. DBG_OUT_HRESULT(hr);
  45. break;
  46. }
  47. if (IsEqualIID(riid, IID_IUnknown))
  48. {
  49. *ppvObj = (IUnknown*)(IPersistStream*)this;
  50. }
  51. else if (IsEqualIID(riid, IID_ISnapinAbout))
  52. {
  53. *ppvObj = (IUnknown*)(ISnapinAbout*)this;
  54. }
  55. else
  56. {
  57. hr = E_NOINTERFACE;
  58. #if (DBG == 1)
  59. LPOLESTR pwszIID;
  60. StringFromIID(riid, &pwszIID);
  61. Dbg(DEB_ERROR, "CSnapinAbout::QI no interface %ws\n", pwszIID);
  62. CoTaskMemFree(pwszIID);
  63. #endif // (DBG == 1)
  64. }
  65. if (FAILED(hr))
  66. {
  67. *ppvObj = NULL;
  68. break;
  69. }
  70. //
  71. // If we got this far we are handing out a new interface pointer on
  72. // this object, so addref it.
  73. //
  74. AddRef();
  75. } while (0);
  76. return hr;
  77. }
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Member: CSnapinAbout::AddRef
  81. //
  82. // Synopsis: Standard OLE
  83. //
  84. // History: 02-10-1999 DavidMun Created
  85. //
  86. //----------------------------------------------------------------------------
  87. STDMETHODIMP_(ULONG)
  88. CSnapinAbout::AddRef()
  89. {
  90. return InterlockedIncrement((LONG *) &_cRefs);
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Member: CSnapinAbout::Release
  95. //
  96. // Synopsis: Standard OLE
  97. //
  98. // History: 02-10-1999 DavidMun Created
  99. //
  100. //----------------------------------------------------------------------------
  101. STDMETHODIMP_(ULONG)
  102. CSnapinAbout::Release()
  103. {
  104. ULONG cRefsTemp;
  105. cRefsTemp = InterlockedDecrement((LONG *)&_cRefs);
  106. if (0 == cRefsTemp)
  107. {
  108. delete this;
  109. }
  110. return cRefsTemp;
  111. }
  112. //============================================================================
  113. //
  114. // ISnapinAbout implementation
  115. //
  116. //============================================================================
  117. //+--------------------------------------------------------------------------
  118. //
  119. // Member: CSnapinAbout::GetSnapinDescription
  120. //
  121. // Synopsis: Return a copy of the description string.
  122. //
  123. // Arguments: [lpDescription] - filled with string
  124. //
  125. // Returns: S_OK or E_OUTOFMEMORY
  126. //
  127. // Modifies: *[lpDescription]
  128. //
  129. // History: 2-09-1999 DavidMun Created
  130. //
  131. // Notes: Caller must CoTaskMemFree returned string
  132. //
  133. //---------------------------------------------------------------------------
  134. STDMETHODIMP
  135. CSnapinAbout::GetSnapinDescription(
  136. LPOLESTR *lpDescription)
  137. {
  138. TRACE_METHOD(CSnapinAbout, GetSnapinDescription);
  139. ASSERT(!IsBadWritePtr(lpDescription, sizeof(*lpDescription)));
  140. WCHAR wzDescription[MAX_PATH];
  141. LoadStr(IDS_SNAPIN_ABOUT_DESCRIPTION, wzDescription, ARRAYLEN(wzDescription));
  142. return CoTaskDupStr(lpDescription, wzDescription);
  143. }
  144. //+--------------------------------------------------------------------------
  145. //
  146. // Member: CSnapinAbout::GetProvider
  147. //
  148. // Synopsis: Return a copy of the provider string.
  149. //
  150. // Arguments: [lpName] - filled with string
  151. //
  152. // Returns: S_OK or E_OUTOFMEMORY
  153. //
  154. // Modifies: *[lpName]
  155. //
  156. // History: 2-09-1999 DavidMun Created
  157. //
  158. // Notes: Caller must CoTaskMemFree returned string
  159. //
  160. //---------------------------------------------------------------------------
  161. STDMETHODIMP
  162. CSnapinAbout::GetProvider(
  163. LPOLESTR *lpName)
  164. {
  165. TRACE_METHOD(CSnapinAbout, GetProvider);
  166. ASSERT(!IsBadWritePtr(lpName, sizeof(*lpName)));
  167. WCHAR wzProvider[MAX_PATH];
  168. LoadStr(IDS_SNAPIN_ABOUT_PROVIDER_NAME, wzProvider, ARRAYLEN(wzProvider));
  169. return CoTaskDupStr(lpName, wzProvider);
  170. }
  171. //+--------------------------------------------------------------------------
  172. //
  173. // Member: CSnapinAbout::GetSnapinVersion
  174. //
  175. // Synopsis: Return a copy of the version string.
  176. //
  177. // Arguments: [lpVersion] - filled with string
  178. //
  179. // Returns: S_OK or E_OUTOFMEMORY
  180. //
  181. // Modifies: *[lpVersion]
  182. //
  183. // History: 2-09-1999 DavidMun Created
  184. //
  185. // Notes: Caller must CoTaskMemFree returned string
  186. //
  187. //---------------------------------------------------------------------------
  188. STDMETHODIMP
  189. CSnapinAbout::GetSnapinVersion(
  190. LPOLESTR *lpVersion)
  191. {
  192. TRACE_METHOD(CSnapinAbout, GetSnapinVersion);
  193. ASSERT(!IsBadWritePtr(lpVersion, sizeof(*lpVersion)));
  194. // 602542-2002/04/16-JonN
  195. // If you store VER_PRODUCTVERSION_STR in a string resource,
  196. // MUI breaks every time the version number is updated.
  197. // Just keep this in the program data.
  198. return CoTaskDupStr(lpVersion, LVER_PRODUCTVERSION_STR);
  199. }
  200. //+--------------------------------------------------------------------------
  201. //
  202. // Member: CSnapinAbout::GetSnapinImage
  203. //
  204. // Synopsis: Fill *[phAppIcon] with the icon representing this snapin.
  205. //
  206. // History: 2-09-1999 DavidMun Created
  207. //
  208. // Notes: This icon is used in the About box invoked from the wizard.
  209. //
  210. //---------------------------------------------------------------------------
  211. STDMETHODIMP
  212. CSnapinAbout::GetSnapinImage(
  213. HICON *phAppIcon)
  214. {
  215. TRACE_METHOD(CSnapinAbout, GetSnapinImage);
  216. ASSERT(!IsBadWritePtr(phAppIcon, sizeof(*phAppIcon)));
  217. *phAppIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_SNAPIN));
  218. return *phAppIcon ? S_OK : HRESULT_FROM_LASTERROR;
  219. }
  220. //+--------------------------------------------------------------------------
  221. //
  222. // Member: CSnapinAbout::GetStaticFolderImage
  223. //
  224. // Synopsis:
  225. //
  226. // Arguments: [phSmallImage] - filled with handle to small image
  227. // [phSmallImageOpen] - filled with handle to small image
  228. // [phLargeImage] - filled with handle to large image
  229. // [pcMask] - filled with bitmap mask color
  230. //
  231. // Returns: HRESULT
  232. //
  233. // Modifies: all out parameters
  234. //
  235. // History: 2-09-1999 DavidMun Created
  236. //
  237. //---------------------------------------------------------------------------
  238. STDMETHODIMP
  239. CSnapinAbout::GetStaticFolderImage(
  240. HBITMAP *phSmallImage,
  241. HBITMAP *phSmallImageOpen,
  242. HBITMAP *phLargeImage,
  243. COLORREF *pcMask)
  244. {
  245. TRACE_METHOD(CSnapinAbout, GetStaticFolderImage);
  246. HRESULT hr = S_OK;
  247. do
  248. {
  249. *pcMask = BITMAP_MASK_COLOR;
  250. *phSmallImage = NULL;
  251. *phSmallImageOpen = NULL;
  252. *phLargeImage = NULL;
  253. *phSmallImage = LoadBitmap(g_hinst,
  254. MAKEINTRESOURCE(IDB_STATIC_FOLDER_CLOSED));
  255. if (!*phSmallImage)
  256. {
  257. hr = HRESULT_FROM_LASTERROR;
  258. DBG_OUT_HRESULT(hr);
  259. break;
  260. }
  261. *phSmallImageOpen = (HBITMAP)
  262. LoadImage(g_hinst,
  263. MAKEINTRESOURCE(IDB_STATIC_FOLDER_OPEN),
  264. IMAGE_BITMAP,
  265. 0,
  266. 0,
  267. 0);
  268. if (!*phSmallImageOpen)
  269. {
  270. hr = HRESULT_FROM_LASTERROR;
  271. DBG_OUT_HRESULT(hr);
  272. DeleteObject(*phSmallImage);
  273. *phSmallImage = NULL;
  274. break;
  275. }
  276. *phLargeImage = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_32x32));
  277. if (!*phLargeImage)
  278. {
  279. hr = HRESULT_FROM_LASTERROR;
  280. DBG_OUT_HRESULT(hr);
  281. DeleteObject(*phSmallImage);
  282. *phSmallImage = NULL;
  283. DeleteObject(*phSmallImageOpen);
  284. *phSmallImageOpen = NULL;
  285. break;
  286. }
  287. } while (0);
  288. return hr;
  289. }
  290. //+--------------------------------------------------------------------------
  291. //
  292. // Member: CSnapinAbout::CSnapinAbout
  293. //
  294. // Synopsis: ctor
  295. //
  296. // History: 2-10-1999 DavidMun Created
  297. //
  298. //---------------------------------------------------------------------------
  299. CSnapinAbout::CSnapinAbout():
  300. _cRefs(1)
  301. {
  302. TRACE_CONSTRUCTOR(CSnapinAbout);
  303. DEBUG_INCREMENT_INSTANCE_COUNTER(CSnapin);
  304. }
  305. //+--------------------------------------------------------------------------
  306. //
  307. // Member: CSnapinAbout::~CSnapinAbout
  308. //
  309. // Synopsis: dtor
  310. //
  311. // History: 2-10-1999 DavidMun Created
  312. //
  313. //---------------------------------------------------------------------------
  314. CSnapinAbout::~CSnapinAbout()
  315. {
  316. TRACE_DESTRUCTOR(CSnapinAbout);
  317. DEBUG_DECREMENT_INSTANCE_COUNTER(CSnapin);
  318. }