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.

260 lines
6.2 KiB

  1. #include "about.h"
  2. #include "resource.h"
  3. #include "globals.h"
  4. #include "uddi.h"
  5. #include <crtdbg.h>
  6. #include <atlbase.h>
  7. CSnapinAbout::CSnapinAbout()
  8. : m_cref(0)
  9. {
  10. OBJECT_CREATED
  11. m_hSmallImage = (HBITMAP) LoadImage( g_hinst, MAKEINTRESOURCE(IDB_SMBMP), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT );
  12. m_hLargeImage = (HBITMAP) LoadImage( g_hinst, MAKEINTRESOURCE(IDB_LGBMP), IMAGE_BITMAP, 32, 32, LR_LOADTRANSPARENT );
  13. m_hSmallImageOpen = (HBITMAP)LoadImage( g_hinst, MAKEINTRESOURCE(IDB_SMBMP), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT );
  14. m_hAppIcon = LoadIcon( g_hinst, MAKEINTRESOURCE( IDI_UDDIMMC ) );
  15. }
  16. CSnapinAbout::~CSnapinAbout()
  17. {
  18. if( m_hSmallImage != NULL )
  19. FreeResource( m_hSmallImage );
  20. if( m_hLargeImage != NULL )
  21. FreeResource( m_hLargeImage );
  22. if( m_hSmallImageOpen != NULL )
  23. FreeResource( m_hSmallImageOpen );
  24. if( m_hAppIcon != NULL )
  25. FreeResource( m_hAppIcon );
  26. m_hSmallImage = NULL;
  27. m_hLargeImage = NULL;
  28. m_hSmallImageOpen = NULL;
  29. m_hAppIcon = NULL;
  30. OBJECT_DESTROYED
  31. }
  32. ///////////////////////
  33. // IUnknown implementation
  34. ///////////////////////
  35. STDMETHODIMP CSnapinAbout::QueryInterface(REFIID riid, LPVOID *ppv)
  36. {
  37. if( !ppv )
  38. return E_FAIL;
  39. *ppv = NULL;
  40. if( IsEqualIID( riid, IID_IUnknown ) )
  41. *ppv = static_cast<ISnapinAbout *>(this);
  42. else if( IsEqualIID( riid, IID_ISnapinAbout ) )
  43. *ppv = static_cast<ISnapinAbout *>(this);
  44. if( *ppv )
  45. {
  46. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  47. return S_OK;
  48. }
  49. return E_NOINTERFACE;
  50. }
  51. STDMETHODIMP_(ULONG) CSnapinAbout::AddRef()
  52. {
  53. return InterlockedIncrement( (LONG *)&m_cref );
  54. }
  55. STDMETHODIMP_(ULONG) CSnapinAbout::Release()
  56. {
  57. if( 0 == InterlockedDecrement( (LONG *)&m_cref ) )
  58. {
  59. //
  60. // we need to decrement our object count in the DLL
  61. //
  62. delete this;
  63. return 0;
  64. }
  65. return m_cref;
  66. }
  67. ///////////////////////////////
  68. // Interface ISnapinAbout
  69. ///////////////////////////////
  70. STDMETHODIMP CSnapinAbout::GetSnapinDescription( /* [out] */ LPOLESTR *lpDescription )
  71. {
  72. if( NULL == lpDescription )
  73. {
  74. return E_INVALIDARG;
  75. }
  76. _TCHAR szDesc[MAX_PATH];
  77. memset( szDesc, 0, MAX_PATH * sizeof( _TCHAR ) );
  78. LoadString( g_hinst, IDS_UDDIMMC_SNAPINDESC, szDesc, ARRAYLEN( szDesc ) );
  79. return AllocOleStr( lpDescription, szDesc );
  80. }
  81. STDMETHODIMP CSnapinAbout::GetProvider( /* [out] */ LPOLESTR *lpName )
  82. {
  83. if( NULL == lpName )
  84. {
  85. return E_INVALIDARG;
  86. }
  87. _TCHAR szProvider[ MAX_PATH ];
  88. memset( szProvider, 0, MAX_PATH * sizeof( _TCHAR ) );
  89. LoadString( g_hinst, IDS_UDDIMMC_PROVIDER, szProvider, ARRAYLEN( szProvider ) );
  90. return AllocOleStr( lpName, szProvider );;
  91. }
  92. STDMETHODIMP CSnapinAbout::GetSnapinVersion( /* [out] */ LPOLESTR *lpVersion )
  93. {
  94. if( NULL == lpVersion )
  95. {
  96. return E_INVALIDARG;
  97. }
  98. USES_CONVERSION;
  99. TCHAR szBuf[ MAX_PATH + 1 ] = {0};
  100. DWORD dwLen = GetModuleFileName( g_hinst, szBuf, MAX_PATH + 1 );
  101. szBuf[ MAX_PATH ] = NULL;
  102. if( dwLen < MAX_PATH )
  103. {
  104. LPDWORD pTranslation = NULL;
  105. UINT uNumTranslation = 0;
  106. DWORD dwHandle = NULL;
  107. DWORD dwSize = GetFileVersionInfoSize( szBuf, &dwHandle );
  108. if( !dwSize )
  109. return E_FAIL;
  110. BYTE* pVersionInfo = new BYTE[dwSize];
  111. if( !pVersionInfo )
  112. return E_OUTOFMEMORY;
  113. if( !GetFileVersionInfo( szBuf, dwHandle, dwSize, pVersionInfo ) ||
  114. !VerQueryValue( (const LPVOID)pVersionInfo, _T("\\VarFileInfo\\Translation"), (LPVOID*)&pTranslation, &uNumTranslation ) ||
  115. !pTranslation )
  116. {
  117. delete [] pVersionInfo;
  118. pVersionInfo = NULL;
  119. pTranslation = NULL;
  120. uNumTranslation = 0;
  121. return E_FAIL;
  122. }
  123. uNumTranslation /= sizeof(DWORD);
  124. tstring strQuery = _T("\\StringFileInfo\\");
  125. //
  126. // 8 characters for the language/char-set,
  127. // 1 for the slash,
  128. // 1 for terminating NULL
  129. //
  130. TCHAR szTranslation[ 128 ] = {0};
  131. _sntprintf( szTranslation, 127, _T("%04x%04x\\"), LOWORD(*pTranslation), HIWORD(*pTranslation) );
  132. try
  133. {
  134. strQuery += szTranslation;
  135. strQuery += _T("FileVersion");
  136. }
  137. catch( ... )
  138. {
  139. delete [] pVersionInfo;
  140. return E_OUTOFMEMORY;
  141. }
  142. LPBYTE lpVerValue = NULL;
  143. UINT uSize = 0;
  144. if( !VerQueryValue(pVersionInfo, (LPTSTR)strQuery.c_str(), (LPVOID *)&lpVerValue, &uSize) )
  145. {
  146. delete [] pVersionInfo;
  147. return E_FAIL;
  148. }
  149. //
  150. // Check the version
  151. //
  152. _tcsncpy( szBuf, (LPTSTR)lpVerValue, MAX_PATH-1 );
  153. delete [] pVersionInfo;
  154. }
  155. *lpVersion = (LPOLESTR)CoTaskMemAlloc( (lstrlen(szBuf) + 1) * sizeof(OLECHAR) );
  156. if( NULL == *lpVersion )
  157. return E_OUTOFMEMORY;
  158. ocscpy( *lpVersion, T2OLE(szBuf) );
  159. return S_OK;
  160. }
  161. STDMETHODIMP CSnapinAbout::GetSnapinImage( /* [out] */ HICON *hAppIcon )
  162. {
  163. *hAppIcon = m_hAppIcon;
  164. if( NULL == *hAppIcon )
  165. return E_FAIL;
  166. else
  167. return S_OK;
  168. }
  169. STDMETHODIMP CSnapinAbout::GetStaticFolderImage(
  170. /* [out] */ HBITMAP *hSmallImage,
  171. /* [out] */ HBITMAP *hSmallImageOpen,
  172. /* [out] */ HBITMAP *hLargeImage,
  173. /* [out] */ COLORREF *cMask )
  174. {
  175. *hSmallImage = m_hSmallImage;
  176. *hLargeImage = m_hLargeImage;
  177. *hSmallImageOpen = m_hSmallImageOpen;
  178. *cMask = RGB(255, 255, 255);
  179. if( ( NULL == *hSmallImage ) || ( NULL == *hLargeImage ) || ( NULL == *hSmallImageOpen ) )
  180. return E_FAIL;
  181. else
  182. return S_OK;
  183. }
  184. //
  185. // This allocates a chunk of memory using CoTaskMemAlloc and copies our chars into it
  186. //
  187. HRESULT CSnapinAbout::AllocOleStr( LPOLESTR *lpDest, _TCHAR *szBuffer )
  188. {
  189. if( ( NULL == lpDest ) || ( NULL == szBuffer ) )
  190. {
  191. return E_INVALIDARG;
  192. }
  193. int iLen = _tcslen( szBuffer );
  194. *lpDest = reinterpret_cast<LPOLESTR>( ::CoTaskMemAlloc( ( iLen + 1 ) * sizeof( _TCHAR ) ) );
  195. if( NULL == *lpDest )
  196. {
  197. return E_OUTOFMEMORY;
  198. }
  199. _tcsncpy( *lpDest, szBuffer, iLen );
  200. (*lpDest)[iLen] = NULL;
  201. return S_OK;
  202. }