⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtwinver.cpp

📁 DtWinVer is a C++ class which provides a comprehensive method to determine which OS the program that
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   
  //Clean up the module instance
  if (hUserInst)
    FreeLibrary(hUserInst);
    
  return rVal;  
}

LONG COSVersion::RegQueryValueEx(HKEY32 hKey, LPSTR lpszValueName, LPDWORD lpdwReserved, LPDWORD lpdwType, LPBYTE lpbData, LPDWORD lpcbData)
{                                             
  //Assume the worst
  DWORD dwResult = ERROR_CALL_NOT_IMPLEMENTED;

  if (m_lpfnRegQueryValueExA)
    dwResult = m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 6, 0x3e, m_lpfnRegQueryValueExA, hKey, lpszValueName, lpdwReserved, lpdwType, lpbData, lpcbData);

  return dwResult;
}                 

BOOL COSVersion::GetVersionEx(LPOSVERSIONINFO lpVersionInfo)
{
  //Assume the worst
  BOOL bSuccess = FALSE;

  if (m_lpfnGetVersionExA)
    bSuccess = (BOOL) m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 1, 1, m_lpfnGetVersionExA, lpVersionInfo, 0);

  return bSuccess;
}

void COSVersion::GetProcessorType(LPOS_VERSION_INFO lpVersionInformation)
{
  //Get the processor details
  SYSTEM_INFO EmulatedSI;
  EmulatedSI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;
  SYSTEM_INFO UnderlyingSI;
  UnderlyingSI.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;

  if (m_lpfnGetNativeSystemInfo)
  {
    m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 1, 1, m_lpfnGetNativeSystemInfo, &UnderlyingSI, 0);
  
    if (m_lpfnGetSystemInfo)
      m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 1, 1, m_lpfnGetSystemInfo, &EmulatedSI, 0);
  }
  else
  {
    if (m_lpfnGetSystemInfo)
      m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 1, 1, m_lpfnGetSystemInfo, &EmulatedSI, 0);

    memcpy(&EmulatedSI, &UnderlyingSI, sizeof(SYSTEM_INFO));
  }

  //Map from the SYTEM_INFO wProcessorArchitecture defines to our equivalents
  switch (UnderlyingSI.wProcessorArchitecture)
  {
    case PROCESSOR_ARCHITECTURE_INTEL: //deliberate fallthrough
    case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
    {
      lpVersionInformation->UnderlyingProcessorType = IA32_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_MSIL:
    {
      lpVersionInformation->UnderlyingProcessorType = MSIL_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_MIPS:
    {
      lpVersionInformation->UnderlyingProcessorType = MIPS_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ARM:
    {
      lpVersionInformation->UnderlyingProcessorType = ARM_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_SHX:
    {
      lpVersionInformation->UnderlyingProcessorType = SHX_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ALPHA:
    {
      lpVersionInformation->UnderlyingProcessorType = ALPHA_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ALPHA64:
    {
      lpVersionInformation->UnderlyingProcessorType = ALPHA64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_PPC:
    {
      lpVersionInformation->UnderlyingProcessorType = PPC_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_IA64:
    {
      lpVersionInformation->UnderlyingProcessorType = IA64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_AMD64:
    {
      lpVersionInformation->UnderlyingProcessorType = AMD64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_UNKNOWN: //Deliberate fallthrough
    default:
    {
      lpVersionInformation->UnderlyingProcessorType = UNKNOWN_PROCESSOR;
      break;
    }
  }
  switch (EmulatedSI.wProcessorArchitecture)
  {
    case PROCESSOR_ARCHITECTURE_INTEL: //deliberate fallthrough
    case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
    {
      lpVersionInformation->EmulatedProcessorType = IA32_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_MSIL:
    {
      lpVersionInformation->EmulatedProcessorType = MSIL_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_MIPS:
    {
      lpVersionInformation->EmulatedProcessorType = MIPS_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ARM:
    {
      lpVersionInformation->EmulatedProcessorType = ARM_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_SHX:
    {
      lpVersionInformation->EmulatedProcessorType = SHX_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ALPHA:
    {
      lpVersionInformation->EmulatedProcessorType = ALPHA_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_ALPHA64:
    {
      lpVersionInformation->EmulatedProcessorType = ALPHA64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_PPC:
    {
      lpVersionInformation->EmulatedProcessorType = PPC_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_IA64:
    {
      lpVersionInformation->EmulatedProcessorType = IA64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_AMD64:
    {
      lpVersionInformation->EmulatedProcessorType = AMD64_PROCESSOR;
      break;
    }
    case PROCESSOR_ARCHITECTURE_UNKNOWN: //Deliberate fallthrough
    default:
    {
      lpVersionInformation->EmulatedProcessorType = UNKNOWN_PROCESSOR;
      break;
    }
  }
}

DWORD COSVersion::GetVersion()
{
  //Assume the worst
  DWORD dwVersion = 0;

  if (m_lpfnGetVersion)
    dwVersion = (BOOL) m_lpfnCallProcEx32W(CPEX_DEST_STDCALL | 0, 0, m_lpfnGetVersion, 0);

  return dwVersion;
}
#endif //defined(_WINDOWS) && !defined(_WIN32)

BOOL COSVersion::GetVersion(LPOS_VERSION_INFO lpVersionInformation)
{
  //Zero out everything in the structure
  memset(lpVersionInformation, 0, sizeof(OS_VERSION_INFO));
                
  #ifdef UNDER_CE
    OSVERSIONINFO osvi;
    memset(&osvi, 0, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    if (!GetVersionEx(&osvi))
      return FALSE;

    //Basic OS info
    lpVersionInformation->dwUnderlyingMajorVersion = osvi.dwMajorVersion; 
    lpVersionInformation->dwUnderlyingMinorVersion = osvi.dwMinorVersion; 
    lpVersionInformation->dwUnderlyingBuildNumber = LOWORD(osvi.dwBuildNumber); //ignore HIWORD
    lpVersionInformation->UnderlyingPlatform = WindowsCE;
    _tcscpy(lpVersionInformation->szUnderlyingCSDVersion, osvi.szCSDVersion);

    //OEM Info
    _tcscpy(lpVersionInformation->szOEMInfo, _T(""));
    SystemParametersInfo(SPI_GETOEMINFO, 256, lpVersionInformation->szOEMInfo, 0);

    //Platform Type
    _tcscpy(lpVersionInformation->szPlatformType, _T(""));
    SystemParametersInfo(SPI_GETPLATFORMTYPE, 256, lpVersionInformation->szPlatformType, 0);

    //Always set the OSType to Workstation on CE. The variable itself does not make 
    //much sense on CE, but we do not conditionally compile it out on CE as then we
    //would have to put in loadsa ifdefs UNDER_CE in the COSVersion::Is... methods
    lpVersionInformation->OSType = Workstation;

  #elif defined(_WIN32) || defined(_WIN64)
    //determine dynamically if GetVersionEx is available, if 
    //not then drop back to using GetVersion

    // Get Kernel handle
    HMODULE hKernel32 = GetModuleHandle(_T("KERNEL32.DLL"));
    if (hKernel32 == NULL)
      return FALSE;

    #ifdef _UNICODE
      lpfnGetVersionEx lpGetVersionEx = (lpfnGetVersionEx) GetProcAddress(hKernel32, "GetVersionExW");
    #else
      lpfnGetVersionEx lpGetVersionEx = (lpfnGetVersionEx) GetProcAddress(hKernel32, "GetVersionExA");
    #endif

    if (lpGetVersionEx)
    {
      OSVERSIONINFOEX osviex;
      memset(&osviex, 0, sizeof(OSVERSIONINFOEX));
      osviex.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

      OSVERSIONINFO osvi;
      memset(&osvi, 0, sizeof(OSVERSIONINFO));
      osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

      BOOL bGotOSviEx = lpGetVersionEx((LPOSVERSIONINFO) &osviex);
      if (!bGotOSviEx)
      {
        if (!lpGetVersionEx(&osvi))
          return FALSE;
      }

      if (bGotOSviEx)
      {
        lpVersionInformation->dwEmulatedMajorVersion = osviex.dwMajorVersion;
        lpVersionInformation->dwEmulatedMinorVersion = osviex.dwMinorVersion;
        lpVersionInformation->dwEmulatedBuildNumber = LOWORD(osviex.dwBuildNumber);
        _tcscpy(lpVersionInformation->szEmulatedCSDVersion, osviex.szCSDVersion);
        lpVersionInformation->wEmulatedServicePackMajor = osviex.wServicePackMajor;
        lpVersionInformation->wEmulatedServicePackMinor = osviex.wServicePackMinor;
        
        //Explicitly map the Win32 wSuiteMask to our own values
        if (osviex.wSuiteMask & VER_SUITE_SMALLBUSINESS)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_SMALLBUSINESS;
        if (osviex.wSuiteMask & VER_SUITE_ENTERPRISE)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_ENTERPRISE;
        if (osviex.wSuiteMask & VER_SUITE_TERMINAL)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_TERMINAL;
        if (osviex.wSuiteMask & VER_SUITE_DATACENTER)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_DATACENTER;
        if (osviex.wSuiteMask & VER_SUITE_PERSONAL)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_PERSONAL;
        if (osviex.wSuiteMask & VER_SUITE_BLADE)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_WEBEDITION;
        if (osviex.wSuiteMask & VER_SUITE_EMBEDDEDNT)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_EMBEDDEDNT;
        if (osviex.wSuiteMask & VER_SUITE_SINGLEUSERTS)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_REMOTEADMINMODE_TERMINAL;
        if (osviex.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_COMPUTE_SERVER;
        if (osviex.wSuiteMask & VER_SUITE_STORAGE_SERVER)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_STORAGE_SERVER;
        if (osviex.wSuiteMask & VER_SUITE_SECURITY_APPLIANCE)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_SECURITY_APPLIANCE;
        if (osviex.wSuiteMask & VER_SUITE_BACKOFFICE)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_BACKOFFICE;
        if (osviex.wSuiteMask & VER_SUITE_WH_SERVER)
          lpVersionInformation->dwSuiteMask |= COSVERSION_SUITE_HOME_SERVER;

        //Explicitely map the Win32 wProductType to our own values
        switch (osviex.wProductType)
        {
          case VER_NT_WORKSTATION:
          {
            lpVersionInformation->OSType = Workstation;
            break;
          }
          case VER_NT_DOMAIN_CONTROLLER:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -