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.

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