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.

230 lines
5.3 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. smabout.cpp
  5. Abstract:
  6. Implementation of the ISnapinAbout MMC interface.
  7. --*/
  8. #include "stdafx.h"
  9. #include "smabout.h"
  10. #include <ntverp.h>
  11. CSmLogAbout::CSmLogAbout()
  12. : m_uIdStrDescription ( IDS_SNAPINABOUT_DESCRIPTION ),
  13. m_uIdStrProvider ( IDS_SNAPINABOUT_PROVIDER ),
  14. m_uIdIconImage ( IDI_SMLOGCFG ),
  15. m_uIdBitmapSmallImage ( IDB_SMLOGCFG_16x16 ),
  16. m_uIdBitmapSmallImageOpen ( IDB_SMLOGCFG_16x16 ),
  17. m_uIdBitmapLargeImage ( IDB_SMLOGCFG_32x32 ),
  18. m_crImageMask ( RGB(255, 0, 255) ),
  19. refcount(1) // implicit AddRef
  20. {
  21. // Initialize Resource IDs.
  22. }
  23. CSmLogAbout::~CSmLogAbout()
  24. {
  25. }
  26. ULONG __stdcall
  27. CSmLogAbout::AddRef()
  28. {
  29. return InterlockedIncrement(&refcount);
  30. }
  31. ULONG __stdcall
  32. CSmLogAbout::Release()
  33. {
  34. if (InterlockedDecrement(&refcount) == 0)
  35. {
  36. delete this;
  37. return 0;
  38. }
  39. return refcount;
  40. }
  41. HRESULT __stdcall
  42. CSmLogAbout::QueryInterface(
  43. const IID& interfaceID,
  44. void** interfaceDesired)
  45. {
  46. ASSERT(interfaceDesired);
  47. HRESULT hr = 0;
  48. if (!interfaceDesired)
  49. {
  50. hr = E_INVALIDARG;
  51. return hr;
  52. }
  53. if (interfaceID == IID_IUnknown)
  54. {
  55. *interfaceDesired =
  56. static_cast<IUnknown*>(static_cast<ISnapinAbout*>(this));
  57. }
  58. else if (interfaceID == IID_ISnapinAbout)
  59. {
  60. *interfaceDesired = static_cast<ISnapinAbout*>(this);
  61. }
  62. else
  63. {
  64. *interfaceDesired = 0;
  65. hr = E_NOINTERFACE;
  66. return hr;
  67. }
  68. AddRef();
  69. return S_OK;
  70. }
  71. HRESULT __stdcall
  72. CSmLogAbout::GetSnapinDescription (
  73. OUT LPOLESTR __RPC_FAR *lpDescription )
  74. {
  75. return HrLoadOleString(m_uIdStrDescription, OUT lpDescription);
  76. }
  77. HRESULT __stdcall
  78. CSmLogAbout::GetProvider (
  79. OUT LPOLESTR __RPC_FAR *lpName )
  80. {
  81. return HrLoadOleString(m_uIdStrProvider, OUT lpName);
  82. }
  83. HRESULT __stdcall
  84. CSmLogAbout::GetSnapinVersion (
  85. OUT LPOLESTR __RPC_FAR *lpVersion )
  86. {
  87. return TranslateString(VER_PRODUCTVERSION_STR, lpVersion);
  88. }
  89. HRESULT
  90. CSmLogAbout::TranslateString(
  91. IN LPSTR lpSrc,
  92. OUT LPOLESTR __RPC_FAR *lpDst)
  93. {
  94. int nWChar;
  95. if ( lpDst == NULL ) {
  96. return E_POINTER;
  97. }
  98. nWChar = MultiByteToWideChar(CP_ACP,
  99. 0,
  100. lpSrc,
  101. strlen(lpSrc),
  102. NULL,
  103. 0);
  104. *lpDst = reinterpret_cast<LPOLESTR>
  105. (CoTaskMemAlloc((nWChar + 1) * sizeof(wchar_t)));
  106. if (*lpDst == NULL) {
  107. return E_OUTOFMEMORY;
  108. }
  109. MultiByteToWideChar(CP_ACP,
  110. 0,
  111. lpSrc,
  112. strlen(lpSrc),
  113. *lpDst,
  114. nWChar);
  115. (*lpDst)[nWChar] = L'\0';
  116. return S_OK;
  117. }
  118. HRESULT __stdcall
  119. CSmLogAbout::GetSnapinImage (
  120. OUT HICON __RPC_FAR *hAppIcon )
  121. {
  122. if (hAppIcon == NULL)
  123. return E_POINTER;
  124. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  125. *hAppIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(m_uIdIconImage));
  126. if (*hAppIcon == NULL)
  127. {
  128. ASSERT(FALSE && "Unable to load icon");
  129. return E_FAIL;
  130. }
  131. return S_OK;
  132. }
  133. HRESULT __stdcall
  134. CSmLogAbout::GetStaticFolderImage (
  135. OUT HBITMAP __RPC_FAR *hSmallImage,
  136. OUT HBITMAP __RPC_FAR *hSmallImageOpen,
  137. OUT HBITMAP __RPC_FAR *hLargeImage,
  138. OUT COLORREF __RPC_FAR *crMask )
  139. {
  140. ASSERT(hSmallImage != NULL);
  141. ASSERT(hSmallImageOpen != NULL);
  142. ASSERT(hLargeImage != NULL);
  143. ASSERT(crMask != NULL);
  144. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  145. HINSTANCE hInstance = AfxGetInstanceHandle();
  146. *hSmallImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImage));
  147. *hSmallImageOpen = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImageOpen));
  148. *hLargeImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapLargeImage));
  149. *crMask = m_crImageMask;
  150. #ifdef _DEBUG
  151. if (NULL == *hSmallImage || NULL == *hSmallImageOpen || NULL == *hLargeImage)
  152. {
  153. TRACE0("WRN: CSmLogAbout::GetStaticFolderImage() - Unable to load all the bitmaps.\n");
  154. return E_FAIL;
  155. }
  156. #endif
  157. return S_OK;
  158. }
  159. /////////////////////////////////////////////////////////////////////
  160. // HrLoadOleString()
  161. //
  162. // Load a string from the resource and return pointer to allocated
  163. // OLE string.
  164. //
  165. // HISTORY
  166. // 16-Nov-98 a-kathse Creation from framewrk\stdutils.cpp
  167. //
  168. HRESULT
  169. CSmLogAbout::HrLoadOleString(
  170. UINT uStringId, // IN: String Id to load from the resource
  171. OUT LPOLESTR * ppaszOleString) // OUT: Pointer to pointer to allocated OLE string
  172. {
  173. CString strT; // Temporary string
  174. USES_CONVERSION;
  175. if ( ppaszOleString == NULL ) {
  176. TRACE0("HrLoadOleString() - ppaszOleString is NULL.\n");
  177. return E_POINTER;
  178. }
  179. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Needed for LoadString()
  180. VERIFY( strT.LoadString(uStringId) );
  181. *ppaszOleString = reinterpret_cast<LPOLESTR>
  182. (CoTaskMemAlloc((strT.GetLength() + 1)* sizeof(wchar_t)));
  183. if (*ppaszOleString == NULL)
  184. return E_OUTOFMEMORY;
  185. wcscpy(OUT *ppaszOleString, T2OLE((LPTSTR)(LPCTSTR)strT));
  186. return S_OK;
  187. } // HrLoadOleString()