Source code of Windows XP (NT5)
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.

91 lines
2.3 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: platform.cpp
  6. //
  7. // Creator: PeterWi
  8. //
  9. // Purpose: platform functions.
  10. //
  11. //=======================================================================
  12. #include "pch.h"
  13. #pragma hdrstop
  14. //=======================================================================
  15. //
  16. // fIsPersonalOrProfessional
  17. //
  18. // Determine if machine is personal or professional.
  19. //
  20. // Note: personal is a type of suite of professional.
  21. //
  22. //=======================================================================
  23. BOOL fIsPersonalOrProfessional(void)
  24. {
  25. OSVERSIONINFOEX osver;
  26. ZeroMemory(&osver, sizeof(osver));
  27. osver.dwOSVersionInfoSize = sizeof(osver);
  28. if ( GetVersionEx((OSVERSIONINFO *)&osver) )
  29. {
  30. return (VER_NT_WORKSTATION == osver.wProductType);
  31. }
  32. return FALSE;
  33. }
  34. /////////////////////////////////////////////////////////////
  35. // GetFileVersionStr(...) get version of a file
  36. // and store it in parameter tszbuf in the format
  37. // of "MajorVersion.MinorVersion.BuildNumber.XXX"
  38. // e.g. "5.4.2448.1"
  39. // tszFile : IN stores full path of the file name
  40. // tszbuf : IN stores OS version string
  41. // ubufsize : IN stores size of tszbuf in charaters.
  42. // : must be at least 20 charaters long
  43. // return : S_OK if OS version string got
  44. // : E_INVALIDARG if argument not valid
  45. // : STRSAFE_E_INSUFFICIENT_BUFFER if insufficient buffer
  46. // : E_FAIL if any other error
  47. HRESULT GetFileVersionStr(LPCTSTR tszFile, LPTSTR tszbuf, UINT uSize)
  48. {
  49. DWORD dwVerNumberMS = 0;
  50. DWORD dwVerNumberLS = 0;
  51. HRESULT hr = S_OK;
  52. USES_IU_CONVERSION;
  53. if (uSize < 20 || NULL == tszbuf)
  54. {
  55. hr = E_INVALIDARG;
  56. goto done;
  57. }
  58. LPSTR szTmp = T2A(tszFile);
  59. if (NULL == szTmp)
  60. {
  61. hr = E_OUTOFMEMORY;
  62. goto done;
  63. }
  64. hr = GetVersionFromFileEx(
  65. szTmp,
  66. &dwVerNumberMS,
  67. &dwVerNumberLS,
  68. TRUE);
  69. if (SUCCEEDED(hr) &&
  70. SUCCEEDED(hr = StringCchPrintfEx(
  71. tszbuf, uSize, NULL, NULL, MISTSAFE_STRING_FLAGS, _T("%d.%d.%d.%d"),
  72. HIWORD(dwVerNumberMS),
  73. LOWORD(dwVerNumberMS),
  74. HIWORD(dwVerNumberLS),
  75. LOWORD(dwVerNumberLS))))
  76. {
  77. DEBUGMSG("file version for %S is %S", tszFile, tszbuf);
  78. }
  79. done:
  80. return hr;
  81. }