zoukankan      html  css  js  c++  java
  • 获取编译器版本+系统版本 C代码

    为了验证上一篇的四种编译器切换……写了几行代码……效果是打印当前的编译器信息及系统信息

    #include <windows.h>
    #include <stdio.h>

    int GetSystemBits(void); //判断系统位数32 or 64
    int GetOsInfo(void); //系统信息
    bool GetCompilerVer(void);//编译器信息

    int main()
    {
    GetCompilerVer();
    GetOsInfo();

    return 0;
    }

    bool GetCompilerVer(void)
    {
    //MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
    //MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
    //MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
    //MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
    //MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008)
    //MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005)
    //MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio 2003)
    //MSVC++ 7.0 _MSC_VER == 1300
    //MSVC++ 6.0 _MSC_VER == 1200
    //MSVC++ 5.0 _MSC_VER == 1100
    #ifdef __GNUC__
    printf(" Compiled by gcc-%d.%d.%d ", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
    #elif _MSC_VER
    // printf(" Compiled by %d ", _MSC_VER);
    if (_MSC_VER == 1900)
    printf(" Compiled by VC2015 ");
    else if (_MSC_VER == 1800)
    printf(" Compiled by VC2013 ");
    else if (_MSC_VER == 1700)
    printf(" Compiled by VC2012 ");
    else if (_MSC_VER == 1600)
    printf(" Compiled by VC2010 ");
    else if (_MSC_VER == 1500)
    printf(" Compiled by VC2008 ");
    else if (_MSC_VER == 1400)
    printf(" Compiled by VC2005 ");
    else if (_MSC_VER == 1310)
    printf(" Compiled by VC2003 ");
    else if (_MSC_VER == 1200)
    printf(" Compiled by VC6.0");
    else
    printf(" Compiled by Other VC compiler ");

    #endif // __GNUC__

    #ifdef __GLIBC__
    printf("Glibc version :%d ", __GLIBC__);//C Libraries
    #elif __GLIBCXX__
    printf("Glibc version :%d ", __GLIBCXX__);//C++ Libraries
    #endif // __GLIBC__

    return true;
    }

    int GetSystemBits()
    {
    SYSTEM_INFO si;
    GetSystemInfo(&si);
    if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
    si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
    {
    return 64;
    }
    return 32;
    }

    int GetOsInfo(void)
    {
    SYSTEM_INFO sysInfo;
    OSVERSIONINFOEX osVersion;

    GetSystemInfo(&sysInfo);

    // printf("OemId : %u ", sysInfo.dwOemId);
    // printf("处理器架构 : %u ", sysInfo.wProcessorArchitecture);
    // printf("页面大小 : %u ", sysInfo.dwPageSize);
    // printf("应用程序最小地址 : %u ", sysInfo.lpMinimumApplicationAddress);
    // printf("应用程序最大地址 : %u ", sysInfo.lpMaximumApplicationAddress);
    // printf("处理器掩码 : %u ", sysInfo.dwActiveProcessorMask);
    // printf("处理器数量 : %u ", sysInfo.dwNumberOfProcessors);
    // printf("处理器类型 : %u ", sysInfo.dwProcessorType);
    // printf("虚拟内存分配粒度 : %u ", sysInfo.dwAllocationGranularity);
    // printf("处理器级别 : %u ", sysInfo.wProcessorLevel);
    // printf("处理器版本 : %u ", sysInfo.wProcessorRevision);
    // typedef struct _OSVERSIONINFOEX
    // {
    // DWORD dwOSVersionInfoSize;
    // DWORD dwMajorVersion;
    // DWORD dwMinorVersion;
    // DWORD dwBuildNumber;
    // DWORD dwPlatformId;
    // TCHAR szCSDVersion[128];
    // WORD wServicePackMajor;
    // WORD wServicePackMinor;
    // WORD wSuiteMask;
    // BYTE wProductType;
    // BYTE wReserved;
    // } OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;
    char* osName = NULL;
    char* vmark = NULL;

    osVersion.dwOSVersionInfoSize = sizeof(osVersion);

    if (GetVersionEx((OSVERSIONINFO*)&osVersion))
    {
    //osName
    switch (osVersion.dwMajorVersion) //判断主版本号
    {
    case 4:
    switch (osVersion.dwMinorVersion) //判断次版本号
    {
    case 0:
    if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
    osName = "Microsoft Windows NT 4.0"; //1996年7月发布
    else if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    osName = "Microsoft Windows 95";
    break;
    case 10:
    osName = "Microsoft Windows 98";
    break;
    case 90:
    osName = "Microsoft Windows Me";
    break;
    }
    break;

    case 5:
    switch (osVersion.dwMinorVersion) //再比较dwMinorVersion的值
    {
    case 0:
    osName = "Microsoft Windows 2000"; //1999年12月发布
    break;

    case 1:
    osName = "Microsoft Windows XP"; //2001年8月发布
    break;

    case 2:
    if (osVersion.wProductType == VER_NT_WORKSTATION
    && sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
    {
    osName = "Microsoft Windows XP Professional x64 Edition";
    }
    else if (GetSystemMetrics(SM_SERVERR2) == 0)
    osName = "Microsoft Windows Server 2003"; //2003年3月发布
    else if (GetSystemMetrics(SM_SERVERR2) != 0)
    osName = "Microsoft Windows Server 2003 R2";
    break;
    }
    break;

    case 6:
    switch (osVersion.dwMinorVersion)
    {
    case 0:
    if (osVersion.wProductType == VER_NT_WORKSTATION)
    osName = "Microsoft Windows Vista";
    else
    osName = "Microsoft Windows Server 2008"; //服务器版本
    break;
    case 1:
    if (osVersion.wProductType == VER_NT_WORKSTATION)
    osName = "Microsoft Windows 7";
    else
    osName = "Microsoft Windows Server 2008 R2";
    break;
    case 2:
    if (osVersion.wProductType == VER_NT_WORKSTATION)
    osName = "Windows 8";
    else if (osVersion.wProductType != VER_NT_WORKSTATION)
    osName = "Windows Server 2012";
    break;
    case 3:
    if (osVersion.wProductType == VER_NT_WORKSTATION)
    osName = "Windows 8.1";
    else if (osVersion.wProductType != VER_NT_WORKSTATION)
    osName = "Windows Server 2012 R2";
    break;
    }
    break;
    case 10:
    switch (osVersion.dwMinorVersion)
    {
    case 0:
    if (osVersion.wProductType == VER_NT_WORKSTATION)
    osName = "Windows 10";
    else if (osVersion.wProductType != VER_NT_WORKSTATION)
    osName = "Windows Server 2016";
    break;

    }
    break;
    }

    //osMark
    switch (osVersion.dwMajorVersion)
    {
    //先判断操作系统版本
    case 5:
    switch (osVersion.dwMinorVersion)
    {
    case 0: //Windows 2000
    if (osVersion.wSuiteMask == VER_SUITE_ENTERPRISE)
    vmark = "Advanced Server";
    break;
    case 1: //Windows XP
    if (osVersion.wSuiteMask == VER_SUITE_EMBEDDEDNT)
    vmark = "Embedded";
    else if (osVersion.wSuiteMask == VER_SUITE_PERSONAL)
    vmark = "Home Edition";
    else
    vmark = "Professional";
    break;
    case 2:
    if (GetSystemMetrics(SM_SERVERR2) == 0
    && osVersion.wSuiteMask == VER_SUITE_BLADE) //Windows Server 2003
    vmark = "Web Edition";
    else if (GetSystemMetrics(SM_SERVERR2) == 0
    && osVersion.wSuiteMask == VER_SUITE_COMPUTE_SERVER)
    vmark = "Compute Cluster Edition";
    else if (GetSystemMetrics(SM_SERVERR2) == 0
    && osVersion.wSuiteMask == VER_SUITE_STORAGE_SERVER)
    vmark = "Storage Server";
    else if (GetSystemMetrics(SM_SERVERR2) == 0
    && osVersion.wSuiteMask == VER_SUITE_DATACENTER)
    vmark = "Datacenter Edition";
    else if (GetSystemMetrics(SM_SERVERR2) == 0
    && osVersion.wSuiteMask == VER_SUITE_ENTERPRISE)
    vmark = "Enterprise Edition";
    else if (GetSystemMetrics(SM_SERVERR2) != 0
    && osVersion.wSuiteMask == VER_SUITE_STORAGE_SERVER)
    vmark = "Storage Server";
    break;
    }
    break;

    case 6:
    switch (osVersion.dwMinorVersion)
    {
    case 0:
    if (osVersion.wProductType != VER_NT_WORKSTATION
    && osVersion.wSuiteMask == VER_SUITE_DATACENTER)
    vmark = "Datacenter Server";
    else if (osVersion.wProductType != VER_NT_WORKSTATION
    && osVersion.wSuiteMask == VER_SUITE_ENTERPRISE)
    vmark = "Enterprise";
    else if (osVersion.wProductType == VER_NT_WORKSTATION
    && osVersion.wSuiteMask == VER_SUITE_PERSONAL) //Windows Vista
    vmark = "Home";
    break;
    case 1:
    if (osVersion.wProductType == VER_NT_WORKSTATION
    && osVersion.wSuiteMask == VER_SUITE_SINGLEUSERTS)
    vmark = "Ultimate";

    break;
    }
    break;
    }

    }//if(GetVersionEx((OSVERSIONINFO *)&os))

    printf("%s ", osName);
    printf("%s", vmark);

    printf(" SP%u.%u", osVersion.wServicePackMajor, osVersion.wServicePackMinor);
    printf(" %d位", GetSystemBits());

    printf(" Version %u.%u", osVersion.dwMajorVersion, osVersion.dwMinorVersion);
    printf(" Build %u ", osVersion.dwBuildNumber);
    //printf("PlatformId : %u ", osVersion.dwPlatformId);
    //printf("%x ",osVersion.wSuiteMask);
    return 0;

    }

  • 相关阅读:
    删除ASP.net临时文件的操作步骤
    设置字段必录,但是直接点提交没有检查必录
    JavaWeb-Session
    Java集合类详解 转
    使用COS组件实现文件上传 转
    Java泛型详解 转
    java接口与工厂
    Vector和ArrayList的比较
    ArrayList
    关闭myeclipse自动校验特别是对js文件的校验
  • 原文地址:https://www.cnblogs.com/nalanhairuo/p/6089381.html
Copyright © 2011-2022 走看看