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.

188 lines
4.4 KiB

  1. /*
  2. ***************************************************************************
  3. *
  4. * Copyright (c) 1999 Microsoft Corporation
  5. *
  6. * Module Name: BugRepSysInfo.c
  7. *
  8. * Abstract : Gets language and OS information for bug reporting pages
  9. *
  10. *
  11. * Revision History:
  12. *
  13. * 1999-09-30 : aarvind : Created the file, my first Windows program
  14. *
  15. ***************************************************************************
  16. */
  17. // BugRepSysInfo.cpp : Implementation of CBugRepSysInfo
  18. #include "stdafx.h"
  19. #include "Brp_sysinfo.h"
  20. #include "BugRepSysInfo.h"
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CBugRepSysInfo
  23. static WORD GetLanguageFromFile(const TCHAR* pszFileName, const TCHAR* pszPath);
  24. /*
  25. ***************************************************************************
  26. *
  27. * GetLanguageString
  28. *
  29. * Returns the language found from a file and using the user default
  30. * settings
  31. *
  32. ***************************************************************************
  33. */
  34. STDMETHODIMP CBugRepSysInfo::GetLanguageID(INT *pintLanguage)
  35. {
  36. WORD wLanguage;
  37. TCHAR szSystemPath[MAX_PATH];
  38. // Get the original language from a system file.
  39. if ( !GetSystemDirectory(szSystemPath, MAX_PATH))
  40. {
  41. //
  42. // Handle failure of this function to get system directory
  43. //
  44. return E_FAIL ;
  45. };
  46. //
  47. // Gets the language id, returns zero if a failure occurs
  48. //
  49. if (wLanguage = GetLanguageFromFile(TEXT("user.exe"), szSystemPath))
  50. {
  51. *pintLanguage = (INT) wLanguage ;
  52. }
  53. else {
  54. //
  55. // Handle failure of this function to get language or file information
  56. //
  57. return E_FAIL ;
  58. }
  59. return S_OK;
  60. }
  61. /*
  62. ***************************************************************************
  63. *
  64. * GetOSVersionString
  65. *
  66. * Gets the version information of the operating system
  67. *
  68. ***************************************************************************
  69. */
  70. STDMETHODIMP CBugRepSysInfo::GetOSVersionString(BSTR *pbstrOSVersion)
  71. {
  72. OSVERSIONINFO OSVersionInfo;
  73. DWORD dwPlatformID;
  74. DWORD dwMajorVersion;
  75. DWORD dwMinorVersion;
  76. DWORD dwBuildNumber;
  77. TCHAR szCSDVersion[200];
  78. TCHAR szOSVersion[200];
  79. USES_CONVERSION;
  80. // Get Windows version
  81. OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
  82. if ( GetVersionEx(&OSVersionInfo) )
  83. {
  84. dwMajorVersion = OSVersionInfo.dwMajorVersion;
  85. dwMinorVersion = OSVersionInfo.dwMinorVersion;
  86. dwBuildNumber = OSVersionInfo.dwBuildNumber;
  87. dwPlatformID = OSVersionInfo.dwPlatformId;
  88. lstrcpy(szCSDVersion, OSVersionInfo.szCSDVersion);
  89. //
  90. // Create system information string
  91. //
  92. wsprintf(szOSVersion,"%d.%d.%d %s",dwMajorVersion,dwMinorVersion,LOWORD(dwBuildNumber),szCSDVersion);
  93. *pbstrOSVersion = SysAllocString(T2COLE(szOSVersion));
  94. }
  95. else {
  96. //
  97. // Function to get OS Version failed so do something
  98. //
  99. // Use GetLastError to return error code to script
  100. //
  101. return E_FAIL ;
  102. }
  103. return S_OK;
  104. }
  105. /*
  106. ***************************************************************************
  107. *
  108. * GetLanguageFromFile
  109. *
  110. ***************************************************************************
  111. */
  112. static WORD GetLanguageFromFile(const TCHAR* pszFileName, const TCHAR* pszPath)
  113. {
  114. BYTE FileVersionBuffer[4096];
  115. DWORD *pdwCharSet;
  116. UINT cb;
  117. DWORD dwHandle;
  118. TCHAR szFileAndPath[MAX_PATH];
  119. WORD wLanguage;
  120. lstrcpy(szFileAndPath, pszPath);
  121. lstrcat(szFileAndPath, TEXT("\\"));
  122. lstrcat(szFileAndPath, pszFileName);
  123. memset(&FileVersionBuffer, 0, sizeof FileVersionBuffer);
  124. //
  125. // Set default language value
  126. //
  127. wLanguage = 0;
  128. if (cb = GetFileVersionInfoSize(szFileAndPath, &dwHandle/*ignored*/))
  129. {
  130. cb = (cb <= sizeof FileVersionBuffer ? cb : sizeof FileVersionBuffer);
  131. if (GetFileVersionInfo(szFileAndPath, 0, cb, &FileVersionBuffer))
  132. {
  133. pdwCharSet = 0;
  134. if (VerQueryValue(&FileVersionBuffer, TEXT("\\VarFileInfo\\Translation"), (void**)&pdwCharSet, &cb)
  135. && pdwCharSet && cb)
  136. {
  137. wLanguage = LOWORD(*pdwCharSet);
  138. }
  139. }
  140. }
  141. return wLanguage;
  142. }
  143. STDMETHODIMP CBugRepSysInfo::GetUserDefaultLCID(DWORD *pdwLCID)
  144. {
  145. *pdwLCID = ::GetUserDefaultLCID();
  146. return S_OK;
  147. }
  148. STDMETHODIMP CBugRepSysInfo::GetActiveCP(UINT *pnACP)
  149. {
  150. *pnACP = ::GetACP();
  151. return S_OK;
  152. }