2010-07-05 130 views
2

我得到了一個小問題:構建Windows(32/64位版本)

爲了獲得OS的體系結構,問題是我的編程語言不支持這樣的功能。因此,我需要閱讀這些信息形式的Windows DLL(如kernel32.dll)
我曾嘗試獲取功能GetNativeSystemInfo/GetVersionEx/GetSystemInfo的信息。
不幸的是我不能得到的架構:/

是否有一些其他的功能來讀取任何Windows DLL的架構?
(它dosnt需要是KERNEL32它可以是任何的DLL,但它必須在Win XP +存在)

隨着信息:使用古普塔(SQLWindows /團隊devoloper)

EDIT1 IM:

typedef struct _SYSTEM_INFO { 
    union { 
    DWORD dwOemId; 
    struct { 
     WORD wProcessorArchitecture; 
     WORD wReserved; 
    } ; 
    } ; 
    DWORD  dwPageSize; 
    LPVOID lpMinimumApplicationAddress; 
    LPVOID lpMaximumApplicationAddress; 
    DWORD_PTR dwActiveProcessorMask; 
    DWORD  dwNumberOfProcessors; 
    DWORD  dwProcessorType; 
    DWORD  dwAllocationGranularity; 
    WORD  wProcessorLevel; 
    WORD  wProcessorRevision; 
} SYSTEM_INFO; 

這就是從MSDN信息,我試圖用10和12參數 (Gupta dosnt支持結構)調用此函數。
在32位,我得到:
alt text http://img714.imageshack.us/img714/1954/32bit.gif

在64位,我得到:
alt text http://img691.imageshack.us/img691/8978/64bit.gif

我能得到每次0 OEMID 32位?或者更好的是64位版本的Windows上填寫的OemID everytiem?

Thx求助!

電賀
AURO

回答

3

GetNativeSystemInfo肯定是要使用該功能。如果您的應用是原生64位應用,則GetNativeSystemInfoGetSystemInfo相同;否則,如果它在WOW64下運行,它將返回真正的系統屬性,即使它在模擬的32位環境中運行。

GetNativeSystemInfo填充一個SYSTEM_INFO結構中,wProcessorArchitecture構件,其告訴您系統是否是32位(可能PROCESSOR_ARCHITECTURE_INTEL)或64位(可能PROCESSOR_ARCHITECTURE_AMD64)。

如果你的語言沒有爲這場比賽的勝利API函數的包裝,使用它,你可以聘請LoadLibraryGetProcAddress像往常一樣,和你需要定義當然SYSTEM_INFO結構。

更新

我將定義

typedef struct _SYSTEM_INFO { 
    WORD  wProcessorArchitecture; 
    WORD  wReserved; 
    DWORD  dwPageSize; 
    LPVOID lpMinimumApplicationAddress; 
    LPVOID lpMaximumApplicationAddress; 
    DWORD_PTR dwActiveProcessorMask; 
    DWORD  dwNumberOfProcessors; 
    DWORD  dwProcessorType; 
    DWORD  dwAllocationGranularity; 
    WORD  wProcessorLevel; 
    WORD  wProcessorRevision; 
} SYSTEM_INFO; 

然後wProcessorArchitecture = 0一個(共同的)的32位的系統上,和一個wProcessorArchitecture = 9(共同)的64位系統。這些只是常數PROCESSOR_ARCHITECTURE_INTELPROCESSOR_ARCHITECTURE_AMD64,分別。這些是常見的32位和64位體系結構。 PROCESSOR_ARCHITECTURE_IA64 = 6稍微不常見,肯定是PROCESSOR_ARCHITECTURE_UNKNOWN = 65535

更新

是的,我看到您的問題。在C中,union表示您一次選擇一個。即,結構爲

DWORD  dwOemId; 
DWORD  dwPageSize; 
LPVOID lpMinimumApplicationAddress; 
LPVOID lpMaximumApplicationAddress; 
DWORD_PTR dwActiveProcessorMask; 
DWORD  dwNumberOfProcessors; 
DWORD  dwProcessorType; 
DWORD  dwAllocationGranularity; 
WORD  wProcessorLevel; 
WORD  wProcessorRevision; 

WORD  wProcessorArchitecture; 
WORD  wReserved; 
DWORD  dwPageSize; 
LPVOID lpMinimumApplicationAddress; 
LPVOID lpMaximumApplicationAddress; 
DWORD_PTR dwActiveProcessorMask; 
DWORD  dwNumberOfProcessors; 
DWORD  dwProcessorType; 
DWORD  dwAllocationGranularity; 
WORD  wProcessorLevel; 
WORD  wProcessorRevision; 

由於一個DWORD由儘可能多的字節(4)的兩個單詞(2×2),該替代品只是兩種方式(並命名)整個結構的數據。在我們的案例中,我們對wProcessorArchitecture單詞更感興趣,而不是wProcessorArchitecture的增補dwOemId以及完全不感興趣的單詞wReserved

+0

看到我的EDIT1 ...... – domiSchenk 2010-07-06 06:41:25

+0

看起來像我不能使用GetNativeSystemInfo coze其沒有明確的可讀性。有沒有辦法從註冊表中讀取它? im不知道是否HKLM \ Sorftware \微軟\的Windows NT \ currentVersion \ BuildLabEx保存... – domiSchenk 2010-07-06 07:39:04

+0

它是完全可讀的;看到我的更新。 – 2010-07-06 12:43:07

0

我想你這個樣子,

BOOL SafeGetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) 
{ 
    BOOL bRet = FALSE; 

    do 
    { 
     if (lpSystemInfo == NULL) 
     { 
      break; 
     } 

     typedef void(WINAPI *GetNativeSystemInfoProc) (LPSYSTEM_INFO lpSystemInfo); 
     GetNativeSystemInfoProc pFun = (GetNativeSystemInfoProc)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo"); 
     if (NULL != pFun) 
     { 
      pFun(lpSystemInfo); 
     } 
     else 
     { 
      GetSystemInfo(lpSystemInfo); 
     } 

     bRet = TRUE; 
    } while (FALSE); 
    return bRet; 
} 


BOOL GetOSDisplayString(LPTSTR pszOS) 
{ 
    GRS_USEPRINTF(); 

    OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)}; 
    SYSTEM_INFO si = {}; 
    BOOL bOsVersionInfoEx; 
    DWORD dwType; 

    if(!(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi))) 
    { 
     return FALSE; 
    } 

    //GetSystemInfo(&si); 
    if (SafeGetNativeSystemInfo(&si) == FALSE) 
    { 
     return FALSE; 
    } 

    if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4) 
    { 
     StringCchCopy(pszOS, BUFSIZE, _T("Microsoft ")); 

     if (osvi.dwMajorVersion == 6) 
     { 
      if(0 == osvi.dwMinorVersion) 
      { 
       if(osvi.wProductType == VER_NT_WORKSTATION) 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Windows Vista ")); 
       } 
       else 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2008 ")); 
       } 

      } 
      else if(1 == osvi.dwMinorVersion) 
      { 
       if(osvi.wProductType == VER_NT_WORKSTATION) 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Windows 7 ")); 
       } 
       else 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown ")); 
       } 
      } 
      else 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown ")); 
      } 

      GetProductInfo(6, 0, 0, 0, &dwType); 
      switch(dwType) 
      { 
      case PRODUCT_ULTIMATE: 
       StringCchCat(pszOS, BUFSIZE, _T("Ultimate Edition")); 
       break; 
      case PRODUCT_HOME_PREMIUM: 
       StringCchCat(pszOS, BUFSIZE, _T("Home Premium Edition")); 
       break; 
      case PRODUCT_HOME_BASIC: 
       StringCchCat(pszOS, BUFSIZE, _T("Home Basic Edition")); 
       break; 
      case PRODUCT_ENTERPRISE: 
       StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition")); 
       break; 
      case PRODUCT_BUSINESS: 
       StringCchCat(pszOS, BUFSIZE, _T("Business Edition")); 
       break; 
      case PRODUCT_STARTER: 
       StringCchCat(pszOS, BUFSIZE, _T("Starter Edition")); 
       break; 
      case PRODUCT_CLUSTER_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Cluster Server Edition")); 
       break; 
      case PRODUCT_DATACENTER_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition")); 
       break; 
      case PRODUCT_DATACENTER_SERVER_CORE: 
       StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition (core installation)")); 
       break; 
      case PRODUCT_ENTERPRISE_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition")); 
       break; 
      case PRODUCT_ENTERPRISE_SERVER_CORE: 
       StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition (core installation)")); 
       break; 
      case PRODUCT_ENTERPRISE_SERVER_IA64: 
       StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems")); 
       break; 
      case PRODUCT_SMALLBUSINESS_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Small Business Server")); 
       break; 
      case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: 
       StringCchCat(pszOS, BUFSIZE, _T("Small Business Server Premium Edition")); 
       break; 
      case PRODUCT_STANDARD_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Standard Edition")); 
       break; 
      case PRODUCT_STANDARD_SERVER_CORE: 
       StringCchCat(pszOS, BUFSIZE, _T("Standard Edition (core installation)")); 
       break; 
      case PRODUCT_WEB_SERVER: 
       StringCchCat(pszOS, BUFSIZE, _T("Web Server Edition")); 
       break; 
      } 

      if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T(", 64-bit")); 
      } 
      else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T(", 64-bit")); 
      } 
      else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA64) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T(", 64-bit")); 
      } 
      else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T(", 32-bit")); 
      } 
     } 

     if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) 
     { 
      if(GetSystemMetrics(SM_SERVERR2)) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2003 R2, ")); 
      } 
      else if (osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Windows Storage Server 2003")); 
      } 
      else if(osvi.wProductType == VER_NT_WORKSTATION && 
       si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Windows XP Professional x64 Edition")); 
      } 
      else 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2003, ")); 
      } 
      if (osvi.wProductType != VER_NT_WORKSTATION) 
      { 
       if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) 
       { 
        if(osvi.wSuiteMask & VER_SUITE_DATACENTER) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition for Itanium-based Systems")); 
        } 
        else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems")); 
        } 
       } 

       else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) 
       { 
        if(osvi.wSuiteMask & VER_SUITE_DATACENTER) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Datacenter x64 Edition")); 
        } 
        else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE) 
        {     
         StringCchCat(pszOS, BUFSIZE, _T("Enterprise x64 Edition")); 
        } 
        else 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Standard x64 Edition")); 
        } 
       } 

       else 
       { 
        if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Compute Cluster Edition")); 
        } 
        else if(osvi.wSuiteMask & VER_SUITE_DATACENTER) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition")); 
        } 
        else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition")); 
        } 
        else if (osvi.wSuiteMask & VER_SUITE_BLADE) 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Web Edition")); 
        } 
        else 
        { 
         StringCchCat(pszOS, BUFSIZE, _T("Standard Edition")); 
        } 
       } 
      } 
     } 

     if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) 
     { 
      StringCchCat(pszOS, BUFSIZE, _T("Windows XP ")); 
      if(osvi.wSuiteMask & VER_SUITE_PERSONAL) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Home Edition")); 
      } 
      else 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Professional")); 
      } 
     } 

     if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) 
     { 
      StringCchCat(pszOS, BUFSIZE, _T("Windows 2000 ")); 

      if (osvi.wProductType == VER_NT_WORKSTATION) 
      { 
       StringCchCat(pszOS, BUFSIZE, _T("Professional")); 
      } 
      else 
      { 
       if(osvi.wSuiteMask & VER_SUITE_DATACENTER) 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Datacenter Server")); 
       } 
       else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE) 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Advanced Server")); 
       } 
       else 
       { 
        StringCchCat(pszOS, BUFSIZE, _T("Server")); 
       } 
      } 
     } 

     // Include service pack (if any) and build number. 

     if(_tcslen(osvi.szCSDVersion) > 0) 
     { 
      StringCchCat(pszOS, BUFSIZE, _T(" ")); 
      StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion); 
     } 

     TCHAR buf[80]; 

     StringCchPrintf(buf, 80, _T(" (build %d)"), osvi.dwBuildNumber); 
     StringCchCat(pszOS, BUFSIZE, buf); 

     return TRUE; 
    } 
    else 
    { 
     GRS_PRINTF(_T("This sample does not support this version of Windows.\n")); 
     return FALSE; 
    } 
}