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.

183 lines
4.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: stdabou_.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////
  11. // StdAbout.cpp
  12. //
  13. // Implementation of the ISnapinAbout interface
  14. //
  15. // HISTORY
  16. // 31-Jul-97 t-danm Creation.
  17. /////////////////////////////////////////////////////////////////////
  18. //#include "stdutils.h" // HrLoadOleString()
  19. #include <strsafe.h>
  20. HRESULT
  21. HrCopyToOleString(
  22. const CString& szString,
  23. OUT LPOLESTR* ppaszOleString)
  24. {
  25. if (ppaszOleString == NULL)
  26. {
  27. return E_POINTER;
  28. }
  29. size_t lengthWithNull = (szString.GetLength() + 1);
  30. *ppaszOleString = reinterpret_cast<LPOLESTR>
  31. (CoTaskMemAlloc( lengthWithNull * sizeof(wchar_t) ));
  32. if (*ppaszOleString == NULL)
  33. {
  34. return E_OUTOFMEMORY;
  35. }
  36. // NOTICE-2002/04/18-artm Part of fix for ntraid#ntbug9-540061.
  37. // Using strsafe.h in dbg_.cpp causes dangerous use of wcscpy() in
  38. // this file to be deprecated. Therefore, I've replaced with
  39. // strsafe function that guarantees null termination of destination
  40. // and won't overrun the buffer.
  41. HRESULT hr = StringCchCopyW(
  42. *ppaszOleString, // destination buffer
  43. lengthWithNull, // size of destination buffer including null
  44. static_cast<LPCWSTR>(szString) );
  45. return hr;
  46. }
  47. HRESULT
  48. HrLoadOleString(
  49. UINT uStringId, // IN: String Id to load from the resource
  50. OUT LPOLESTR * ppaszOleString) // OUT: Pointer to pointer to allocated OLE string
  51. {
  52. if (ppaszOleString == NULL)
  53. {
  54. TRACE0("HrLoadOleString() - ppaszOleString is NULL.\n");
  55. return E_POINTER;
  56. }
  57. CString strT; // Temporary string
  58. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Needed for LoadString()
  59. VERIFY( strT.LoadString(uStringId) );
  60. return HrCopyToOleString(strT, ppaszOleString);
  61. } // HrLoadOleString()
  62. CSnapinAbout::CSnapinAbout() :
  63. hBitmapSmallImage(0),
  64. hBitmapSmallImageOpen(0),
  65. hBitmapLargeImage(0)
  66. {
  67. }
  68. CSnapinAbout::~CSnapinAbout()
  69. {
  70. if (hBitmapSmallImage)
  71. {
  72. DeleteObject(hBitmapSmallImage);
  73. hBitmapSmallImage = 0;
  74. }
  75. if (hBitmapSmallImageOpen)
  76. {
  77. DeleteObject(hBitmapSmallImageOpen);
  78. hBitmapSmallImageOpen = 0;
  79. }
  80. if (hBitmapLargeImage)
  81. {
  82. DeleteObject(hBitmapLargeImage);
  83. hBitmapLargeImage = 0;
  84. }
  85. }
  86. STDMETHODIMP CSnapinAbout::GetSnapinDescription(OUT LPOLESTR __RPC_FAR *lpDescription)
  87. {
  88. return HrLoadOleString(m_uIdStrDestription, OUT lpDescription);
  89. }
  90. STDMETHODIMP CSnapinAbout::GetProvider(OUT LPOLESTR __RPC_FAR *lpName)
  91. {
  92. return HrCopyToOleString(m_szProvider, OUT lpName);
  93. }
  94. STDMETHODIMP CSnapinAbout::GetSnapinVersion(OUT LPOLESTR __RPC_FAR *lpVersion)
  95. {
  96. return HrCopyToOleString(m_szVersion, OUT lpVersion);
  97. }
  98. STDMETHODIMP CSnapinAbout::GetSnapinImage(OUT HICON __RPC_FAR *hAppIcon)
  99. {
  100. if (hAppIcon == NULL)
  101. return E_POINTER;
  102. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  103. *hAppIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(m_uIdIconImage));
  104. if (*hAppIcon == NULL)
  105. {
  106. ASSERT(FALSE && "Unable to load icon");
  107. return E_FAIL;
  108. }
  109. return S_OK;
  110. }
  111. STDMETHODIMP CSnapinAbout::GetStaticFolderImage(
  112. OUT HBITMAP __RPC_FAR *hSmallImage,
  113. OUT HBITMAP __RPC_FAR *hSmallImageOpen,
  114. OUT HBITMAP __RPC_FAR *hLargeImage,
  115. OUT COLORREF __RPC_FAR *crMask)
  116. {
  117. ASSERT(hSmallImage != NULL);
  118. ASSERT(hSmallImageOpen != NULL);
  119. ASSERT(hLargeImage != NULL);
  120. ASSERT(crMask != NULL);
  121. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  122. HINSTANCE hInstance = AfxGetInstanceHandle();
  123. if (!hBitmapSmallImage)
  124. {
  125. hBitmapSmallImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImage));
  126. }
  127. ASSERT(hBitmapSmallImage);
  128. *hSmallImage = hBitmapSmallImage;
  129. if (!hBitmapSmallImageOpen)
  130. {
  131. hBitmapSmallImageOpen = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImageOpen));
  132. }
  133. ASSERT(hBitmapSmallImageOpen);
  134. *hSmallImageOpen = hBitmapSmallImageOpen;
  135. if (!hBitmapLargeImage)
  136. {
  137. hBitmapLargeImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapLargeImage));
  138. }
  139. ASSERT(hBitmapLargeImage);
  140. *hLargeImage = hBitmapLargeImage;
  141. *crMask = m_crImageMask;
  142. #ifdef _DEBUG
  143. if (NULL == *hSmallImage || NULL == *hSmallImageOpen || NULL == *hLargeImage)
  144. {
  145. TRACE0("WRN: CSnapinAbout::GetStaticFolderImage() - Unable to load all the bitmaps.\n");
  146. return E_FAIL;
  147. }
  148. #endif
  149. return S_OK;
  150. }