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.

237 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. string.c
  5. Abstract:
  6. This file implements version functions for fax.
  7. Author:
  8. Eran Yariv (erany) 30-Oct-2001
  9. Environment:
  10. User Mode
  11. --*/
  12. #include <windows.h>
  13. #include <tchar.h>
  14. #include <stdlib.h>
  15. #include "faxutil.h"
  16. #include "faxreg.h"
  17. DWORD
  18. GetFileVersion (
  19. LPCTSTR lpctstrFileName,
  20. PFAX_VERSION pVersion
  21. )
  22. /*++
  23. Routine name : GetFileVersion
  24. Routine description:
  25. Fills a FAX_VERSION structure with data about a given file module
  26. Author:
  27. Eran Yariv (EranY), Nov, 1999
  28. Arguments:
  29. lpctstrFileName [in ] - File name
  30. pVersion [out] - Version information
  31. Return Value:
  32. Standard Win32 error
  33. --*/
  34. {
  35. DWORD dwRes = ERROR_SUCCESS;
  36. DWORD dwVerInfoSize;
  37. DWORD dwVerHnd=0; // An ignored parameter, always 0
  38. LPBYTE lpbVffInfo = NULL;
  39. VS_FIXEDFILEINFO *pFixedFileInfo;
  40. UINT uVersionDataLength;
  41. DEBUG_FUNCTION_NAME(TEXT("GetFileVersion"));
  42. if (!pVersion)
  43. {
  44. return ERROR_INVALID_PARAMETER;
  45. }
  46. if (sizeof (FAX_VERSION) != pVersion->dwSizeOfStruct)
  47. {
  48. //
  49. // Size mismatch
  50. //
  51. return ERROR_INVALID_PARAMETER;
  52. }
  53. pVersion->bValid = FALSE;
  54. //
  55. // Find size needed for version information
  56. //
  57. dwVerInfoSize = GetFileVersionInfoSize ((LPTSTR)lpctstrFileName, &dwVerHnd);
  58. if (0 == dwVerInfoSize)
  59. {
  60. dwRes = GetLastError ();
  61. DebugPrintEx(
  62. DEBUG_ERR,
  63. TEXT("GetFileVersionInfoSize() failed . dwRes = %ld"),
  64. dwRes);
  65. return dwRes;
  66. }
  67. //
  68. // Allocate memory for file version info
  69. //
  70. lpbVffInfo = (LPBYTE)MemAlloc (dwVerInfoSize);
  71. if (NULL == lpbVffInfo)
  72. {
  73. DebugPrintEx(
  74. DEBUG_ERR,
  75. TEXT("Cant allocate %ld bytes"),
  76. dwVerInfoSize);
  77. return ERROR_NOT_ENOUGH_MEMORY;
  78. }
  79. //
  80. // Try to get the version info
  81. //
  82. if (!GetFileVersionInfo(
  83. (LPTSTR)lpctstrFileName,
  84. dwVerHnd,
  85. dwVerInfoSize,
  86. (LPVOID)lpbVffInfo))
  87. {
  88. dwRes = GetLastError ();
  89. DebugPrintEx(
  90. DEBUG_ERR,
  91. TEXT("GetFileVersionInfo() failed . dwRes = %ld"),
  92. dwRes);
  93. goto exit;
  94. }
  95. //
  96. // Query the required version structure
  97. //
  98. if (!VerQueryValue (
  99. (LPVOID)lpbVffInfo,
  100. TEXT ("\\"), // Retrieve the VS_FIXEDFILEINFO struct
  101. (LPVOID *)&pFixedFileInfo,
  102. &uVersionDataLength))
  103. {
  104. dwRes = GetLastError ();
  105. DebugPrintEx(
  106. DEBUG_ERR,
  107. TEXT("VerQueryValue() failed . dwRes = %ld"),
  108. dwRes);
  109. goto exit;
  110. }
  111. pVersion->dwFlags = (pFixedFileInfo->dwFileFlags & VS_FF_DEBUG) ? FAX_VER_FLAG_CHECKED : 0;
  112. pVersion->wMajorVersion = WORD((pFixedFileInfo->dwProductVersionMS) >> 16);
  113. pVersion->wMinorVersion = WORD((pFixedFileInfo->dwProductVersionMS) & 0x0000ffff);
  114. pVersion->wMajorBuildNumber = WORD((pFixedFileInfo->dwProductVersionLS) >> 16);
  115. pVersion->wMinorBuildNumber = WORD((pFixedFileInfo->dwProductVersionLS) & 0x0000ffff);
  116. pVersion->bValid = TRUE;
  117. Assert (ERROR_SUCCESS == dwRes);
  118. exit:
  119. if (lpbVffInfo)
  120. {
  121. MemFree (lpbVffInfo);
  122. }
  123. return dwRes;
  124. } // GetFileVersion
  125. #define REG_KEY_IE _T("Software\\Microsoft\\Internet Explorer")
  126. #define REG_VAL_IE_VERSION _T("Version")
  127. ///////////////////////////////////////////////////////////////////////////////////////
  128. // Function:
  129. // GetVersionIE
  130. //
  131. // Purpose:
  132. // Find out the version of IE that is installed on this machine.
  133. // This function can be used on any platform.
  134. // For versions less than 4.0 this function always returns 1.0
  135. //
  136. // Params:
  137. // BOOL* fInstalled - out param, is IE installed?
  138. // INT* iMajorVersion - out param, the major version of IE
  139. // INT* iMinorVersion - out param, the minor version of IE
  140. //
  141. // Return Value:
  142. // ERROR_SUCCESS - in case of success
  143. // Win32 Error code - in case of failure
  144. //
  145. // Author:
  146. // Mooly Beery (MoolyB) 19-May-2002
  147. ///////////////////////////////////////////////////////////////////////////////////////
  148. DWORD GetVersionIE(BOOL* fInstalled, INT* iMajorVersion, INT* iMinorVersion)
  149. {
  150. DWORD dwRet = ERROR_SUCCESS;
  151. LPTSTR lptstrVersion = NULL;
  152. HKEY hKey = NULL;
  153. (*fInstalled) = FALSE;
  154. (*iMajorVersion) = 1;
  155. (*iMinorVersion) = 0;
  156. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,REG_KEY_IE,KEY_READ,FALSE);
  157. if (!hKey)
  158. {
  159. // IE is not installed at all.
  160. goto exit;
  161. }
  162. (*fInstalled) = TRUE;
  163. lptstrVersion = GetRegistryString(hKey,REG_VAL_IE_VERSION,NULL);
  164. if (!lptstrVersion)
  165. {
  166. // no Version entry, this means IE version is less than 4.0
  167. goto exit;
  168. }
  169. // the version is formatted: <major version>.<minor version>.<major build>.<minor build>
  170. LPTSTR lptsrtFirstDot = _tcschr(lptstrVersion,_T('.'));
  171. if (!lptsrtFirstDot)
  172. {
  173. // something is wrong in the format.
  174. dwRet = ERROR_BAD_FORMAT;
  175. goto exit;
  176. }
  177. (*lptsrtFirstDot++) = 0;
  178. (*iMajorVersion) = _ttoi(lptstrVersion);
  179. LPTSTR lptsrtSecondDot = _tcschr(lptsrtFirstDot,_T('.'));
  180. if (!lptsrtSecondDot)
  181. {
  182. // something is wrong in the format.
  183. dwRet = ERROR_BAD_FORMAT;
  184. goto exit;
  185. }
  186. (*lptsrtSecondDot) = 0;
  187. (*iMinorVersion) = _ttoi(lptsrtFirstDot);
  188. exit:
  189. if (hKey)
  190. {
  191. RegCloseKey(hKey);
  192. }
  193. if (lptstrVersion)
  194. {
  195. MemFree(lptstrVersion);
  196. }
  197. return dwRet;
  198. }