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.

396 lines
10 KiB

  1. /*++
  2. Module Name:
  3. DfsAbout.cpp
  4. Abstract:
  5. This module contains the implementation for the ISnapinAbout interface.
  6. Note: ISnapinAbout requires that we do a CoTaskMemAlloc for strings.
  7. --*/
  8. #include "stdafx.h"
  9. #include "DfsGUI.h"
  10. #include "Utils.h" // For LoadResourceFromString
  11. #include "DfsScope.h"
  12. STDMETHODIMP
  13. CDfsSnapinScopeManager::GetSnapinDescription(
  14. OUT LPOLESTR* o_ppaszOleString
  15. )
  16. /*++
  17. Routine Description:
  18. Returns a single string describing our snap-in.
  19. Arguments:
  20. o_ppaszOleString - The pointer in which the description string is stored
  21. Return value:
  22. S_OK, On success
  23. E_INVALIDARG, On null input parameter
  24. --*/
  25. {
  26. RETURN_INVALIDARG_IF_NULL(o_ppaszOleString);
  27. CComBSTR bstrTemp;
  28. HRESULT hr = LoadStringFromResource(IDS_SNAPIN_DESCRIPTION, &bstrTemp);
  29. RETURN_IF_FAILED(hr);
  30. *o_ppaszOleString = reinterpret_cast<LPOLESTR>
  31. (CoTaskMemAlloc((lstrlen(bstrTemp) + 1) * sizeof(wchar_t)));
  32. if (*o_ppaszOleString == NULL)
  33. return E_OUTOFMEMORY;
  34. USES_CONVERSION;
  35. wcscpy(OUT *o_ppaszOleString, T2OLE(bstrTemp));
  36. return S_OK;
  37. }
  38. STDMETHODIMP
  39. CDfsSnapinScopeManager::GetProvider(
  40. OUT LPOLESTR* o_lpszName
  41. )
  42. /*++
  43. Routine Description:
  44. Returns a single string describing this snap-in's provider, that is us.
  45. Arguments:
  46. o_lpszName - The pointer in which the provider string is stored
  47. Return value:
  48. S_OK, On success
  49. E_INVALIDARG, On null input parameter
  50. --*/
  51. {
  52. RETURN_INVALIDARG_IF_NULL(o_lpszName);
  53. // Read the required field from the version info struct
  54. // 040904B0 - Lang-Code Page number
  55. HRESULT hr = ReadFieldFromVersionInfo(
  56. _T("CompanyName"),
  57. o_lpszName
  58. );
  59. RETURN_IF_FAILED(hr);
  60. return S_OK;
  61. }
  62. STDMETHODIMP
  63. CDfsSnapinScopeManager::GetSnapinVersion(
  64. OUT LPOLESTR* o_lpszVersion
  65. )
  66. /*++
  67. Routine Description:
  68. Returns a single string describing this snap-in's version number.
  69. Arguments:
  70. o_lpszVersion - The pointer in which the version is stored
  71. Return value:
  72. S_OK, On success
  73. E_INVALIDARG, On null input parameter
  74. --*/
  75. {
  76. RETURN_INVALIDARG_IF_NULL(o_lpszVersion);
  77. // Read the required field from the version info struct
  78. // 040904B0 - Lang-Code Page number
  79. HRESULT hr = ReadFieldFromVersionInfo(
  80. _T("ProductVersion"),
  81. o_lpszVersion
  82. );
  83. RETURN_IF_FAILED(hr);
  84. return S_OK;
  85. }
  86. //
  87. // MMC makes copies of the returned icon. The snap-in can free the original
  88. // when the ISnapinAbout interface is released.
  89. // It is freed in ~CDfsSnapinScopeManager.
  90. //
  91. STDMETHODIMP
  92. CDfsSnapinScopeManager::GetSnapinImage(
  93. OUT HICON* o_hSnapinIcon
  94. )
  95. {
  96. _ASSERT(o_hSnapinIcon);
  97. if (!m_hSnapinIcon)
  98. {
  99. m_hSnapinIcon = (HICON)LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_MAIN32x32),
  100. IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
  101. if (!m_hSnapinIcon)
  102. return HRESULT_FROM_WIN32(GetLastError());
  103. }
  104. *o_hSnapinIcon = m_hSnapinIcon;
  105. return S_OK;
  106. }
  107. //
  108. // MMC makes copies of the returned bitmaps. The snap-in can free the originals
  109. // when the ISnapinAbout interface is released.
  110. // They are freed in ~CDfsSnapinScopeManager.
  111. //
  112. STDMETHODIMP
  113. CDfsSnapinScopeManager::GetStaticFolderImage(
  114. OUT HBITMAP* o_hSmallImage,
  115. OUT HBITMAP* o_hSmallImageOpen,
  116. OUT HBITMAP* o_hLargeImage,
  117. OUT COLORREF* o_cMask
  118. )
  119. {
  120. _ASSERT(o_hSmallImage);
  121. _ASSERT(o_hSmallImageOpen);
  122. _ASSERT(o_hLargeImage);
  123. _ASSERT(o_cMask);
  124. HRESULT hr = S_OK;
  125. do {
  126. if (!m_hLargeBitmap)
  127. {
  128. m_hLargeBitmap = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_MAIN32x32),
  129. IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  130. if (!m_hLargeBitmap)
  131. {
  132. hr = HRESULT_FROM_WIN32(GetLastError());
  133. break;
  134. }
  135. }
  136. if (!m_hSmallBitmap)
  137. {
  138. m_hSmallBitmap = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_MAIN16x16),
  139. IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  140. if (!m_hSmallBitmap)
  141. {
  142. hr = HRESULT_FROM_WIN32(GetLastError());
  143. break;
  144. }
  145. }
  146. if (!m_hSmallBitmapOpen)
  147. {
  148. m_hSmallBitmapOpen = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_MAIN16x16),
  149. IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  150. if (!m_hSmallBitmapOpen)
  151. {
  152. hr = HRESULT_FROM_WIN32(GetLastError());
  153. break;
  154. }
  155. }
  156. *o_hLargeImage = m_hLargeBitmap;
  157. *o_hSmallImage = m_hSmallBitmap;
  158. *o_hSmallImageOpen = m_hSmallBitmapOpen;
  159. *o_cMask = RGB(255, 0, 255); // color of the 1st pixel: pink
  160. } while (0);
  161. return hr;
  162. }
  163. STDMETHODIMP
  164. CDfsSnapinScopeManager::ReadFieldFromVersionInfo(
  165. IN LPTSTR i_lpszField,
  166. OUT LPOLESTR* o_lpszFieldValue
  167. )
  168. /*++
  169. Routine Description:
  170. Reads and returns a particular field from the binary's version information
  171. block.
  172. Allocates memory for the 'out' parameter using CoTaskMemAlloc.
  173. Arguments:
  174. i_lpszField - The StringFileInfo field whose value is being queried. E.g
  175. ProductName, CompanyName etc.
  176. o_lpszFieldValue - The pointer in which the field value is returned
  177. --*/
  178. {
  179. RETURN_INVALIDARG_IF_NULL(i_lpszField);
  180. RETURN_INVALIDARG_IF_NULL(o_lpszFieldValue);
  181. DWORD dwVerInfoSize = 0; // Size of version information block
  182. DWORD dwIgnored = 0; // An 'ignored' parameter, always '0'
  183. BOOL bRetCode = 0;
  184. CComBSTR bstrBinaryName; // Name of our dll. %%% AC Could not find a way to get this??
  185. UINT uVersionCharLen = 0;
  186. LPOLESTR lpszReadFieldValue = NULL; // Is temporary and is released as part of ver info block.
  187. LPVOID lpVerInfo = NULL; // The version information is read into this
  188. // Load the dll name from resource
  189. HRESULT hr = LoadStringFromResource(IDS_APP_BINARY_NAME, &bstrBinaryName);
  190. RETURN_IF_FAILED(hr);
  191. // Get the size of the version struct
  192. dwVerInfoSize = ::GetFileVersionInfoSize(bstrBinaryName, &dwIgnored);
  193. if (dwVerInfoSize <= 0)
  194. {
  195. return E_UNEXPECTED;
  196. }
  197. lpVerInfo = ::CoTaskMemAlloc(dwVerInfoSize);
  198. RETURN_OUTOFMEMORY_IF_NULL(lpVerInfo);
  199. // Read the version info resource
  200. bRetCode = ::GetFileVersionInfo(bstrBinaryName, dwIgnored, dwVerInfoSize, lpVerInfo);
  201. if (bRetCode <= 0)
  202. {
  203. ::CoTaskMemFree(lpVerInfo);
  204. return E_UNEXPECTED;
  205. }
  206. // First get the Language ID and page.
  207. DWORD dwLangIDAndCodePage = 0;
  208. bRetCode = ::VerQueryValue( (LPVOID)lpVerInfo,
  209. _T("\\VarFileInfo\\Translation"),
  210. (LPVOID *)&lpszReadFieldValue,
  211. &uVersionCharLen);
  212. if (bRetCode <= 0 || NULL == lpszReadFieldValue)
  213. {
  214. ::CoTaskMemFree(lpVerInfo);
  215. return E_UNEXPECTED;
  216. }
  217. dwLangIDAndCodePage = *((DWORD *)lpszReadFieldValue);
  218. // Using the LangId and the code page to form the query for Version Info.
  219. CComBSTR bstrDesiredField;
  220. TCHAR lpzStringOfLangIdCodePage[100];
  221. _stprintf(lpzStringOfLangIdCodePage, _T("%04x%04x"),LOWORD(dwLangIDAndCodePage), HIWORD(dwLangIDAndCodePage));
  222. bstrDesiredField = _T("\\StringFileInfo\\");
  223. bstrDesiredField += lpzStringOfLangIdCodePage;
  224. bstrDesiredField += _T("\\");
  225. bstrDesiredField += i_lpszField;
  226. // Read the Description from the versioninfo resource
  227. bRetCode = ::VerQueryValue( (LPVOID)lpVerInfo,
  228. bstrDesiredField,
  229. (LPVOID *)&lpszReadFieldValue,
  230. &uVersionCharLen);
  231. if (bRetCode <= 0)
  232. {
  233. ::CoTaskMemFree(lpVerInfo);
  234. return E_UNEXPECTED;
  235. }
  236. UINT uBufferLen = uVersionCharLen * sizeof (OLECHAR);
  237. // Allocate the memory and copy the structure
  238. *o_lpszFieldValue = (LPOLESTR)::CoTaskMemAlloc(uBufferLen);
  239. if (!*o_lpszFieldValue)
  240. {
  241. ::CoTaskMemFree(lpVerInfo);
  242. return E_OUTOFMEMORY;
  243. }
  244. memcpy(*o_lpszFieldValue, lpszReadFieldValue, uBufferLen);
  245. ::CoTaskMemFree(lpVerInfo);
  246. return S_OK;
  247. }
  248. STDMETHODIMP
  249. CDfsSnapinScopeManager::GetHelpTopic(
  250. OUT LPOLESTR* o_lpszCompiledHelpFile
  251. )
  252. {
  253. if (o_lpszCompiledHelpFile == NULL)
  254. return E_POINTER;
  255. TCHAR szSystemRoot[MAX_PATH + 1] = _T("");
  256. GetSystemWindowsDirectory(szSystemRoot, MAX_PATH);
  257. CComBSTR bstrRelHelpPath;
  258. HRESULT hr = LoadStringFromResource(IDS_MMC_HELP_FILE_PATH, &bstrRelHelpPath);
  259. if (FAILED(hr))
  260. return hr;
  261. *o_lpszCompiledHelpFile = reinterpret_cast<LPOLESTR>
  262. (CoTaskMemAlloc((_tcslen(szSystemRoot) + _tcslen(bstrRelHelpPath) + 1) * sizeof(wchar_t)));
  263. if (*o_lpszCompiledHelpFile == NULL)
  264. return E_OUTOFMEMORY;
  265. USES_CONVERSION;
  266. wcscpy(*o_lpszCompiledHelpFile, T2OLE(szSystemRoot));
  267. wcscat(*o_lpszCompiledHelpFile, T2OLE((LPTSTR)(LPCTSTR)bstrRelHelpPath));
  268. return S_OK;
  269. }
  270. STDMETHODIMP
  271. CDfsSnapinScopeManager::GetLinkedTopics(
  272. OUT LPOLESTR* o_lpszCompiledHelpFiles
  273. )
  274. {
  275. if (o_lpszCompiledHelpFiles == NULL)
  276. return E_POINTER;
  277. TCHAR szSystemRoot[MAX_PATH + 1] = _T("");
  278. GetSystemWindowsDirectory(szSystemRoot, MAX_PATH);
  279. CComBSTR bstrRelHelpPath;
  280. HRESULT hr = LoadStringFromResource(IDS_LINKED_HELP_FILE_PATH, &bstrRelHelpPath);
  281. if (FAILED(hr))
  282. return hr;
  283. *o_lpszCompiledHelpFiles = reinterpret_cast<LPOLESTR>
  284. (CoTaskMemAlloc((_tcslen(szSystemRoot) + _tcslen(bstrRelHelpPath) + 1) * sizeof(wchar_t)));
  285. if (*o_lpszCompiledHelpFiles == NULL)
  286. return E_OUTOFMEMORY;
  287. USES_CONVERSION;
  288. wcscpy(*o_lpszCompiledHelpFiles, T2OLE(szSystemRoot));
  289. wcscat(*o_lpszCompiledHelpFiles, T2OLE((LPTSTR)(LPCTSTR)bstrRelHelpPath));
  290. return S_OK;
  291. }