2010-07-05 3 views
2

j'ai eu un petit problème:Obtenir l'architecture de Windows (32/64 bit version)

im Tring pour obtenir l'architecture du système d'exploitation, le problème est mon langage de programmation ne marche pas soutenir de telles fonctions. Par conséquent j'ai besoin de lire ce formulaire d'information une DLL de Windows (comme kernel32.dll)
j'ai essayé d'obtenir les informations avec les fonctions GetNativeSystemInfo/GetVersionEx/GetSystemInfo.
Malheureusement, je n'ai pas pu obtenir l'architecture:/

Y at-il d'autres fonctions pour lire l'architecture dans une DLL dll?
(il Dosnt besoin d'être kernel32 il peut être une dll mais il doit exister dans win xp +)

Comme info: im en utilisant Gupta (SQLWindows/devoloper Team)

Edit1:

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; 

thats l'info de MSDN, j'ai essayé d'appeler cette fonction avec 10 et 12 paramètres (Gupta dosnt des structures de support).
Sur 32Bit i get:
alt text http://img714.imageshack.us/img714/1954/32bit.gif

sur 64Bit i get:
alt text http://img691.imageshack.us/img691/8978/64bit.gif

-je obtenir à chaque fois un 0 OemID sur 32 bits? ou mieux est le tout OemID rempli sur la version 64bit de Windows?

Merci à l'aide !!

Salue
Auro

Répondre

3

GetNativeSystemInfo est certainement la fonction à utiliser. Si votre application est une application native 64 bits, GetNativeSystemInfo est identique à GetSystemInfo; Sinon, s'il fonctionne sous WOW64, il renvoie les vraies propriétés système, même si elles sont exécutées dans un environnement 32 bits émulé.

GetNativeSystemInfo remplit une structure SYSTEM_INFO, l'élément de wProcessorArchitecture qui indique si le système est de 32 bits (probablement PROCESSOR_ARCHITECTURE_INTEL) ou 64 bits (probablement PROCESSOR_ARCHITECTURE_AMD64).

Si votre langue ne dispose pas d'une enveloppe pour cette fonction API Win, pour l'utiliser, vous pouvez utiliser LoadLibrary et GetProcAddress comme d'habitude, et vous devez définir la structure SYSTEM_INFO, bien sûr.

Mise à jour

Je définirais

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; 

Puis wProcessorArchitecture = 0 sur un (commun) système 32 bits et wProcessorArchitecture = 9 sur un (commun) système 64 bits. Ce ne sont que les constantes PROCESSOR_ARCHITECTURE_INTEL et PROCESSOR_ARCHITECTURE_AMD64, respectivement. Ce sont les architectures communes 32 bits et 64 bits. PROCESSOR_ARCHITECTURE_IA64 = 6 est légèrement plus rare, comme c'est sûrement PROCESSOR_ARCHITECTURE_UNKNOWN = 65535.

Mise à jour

Oui, je vois votre problème. En C, union signifie que vous choisissez un des options à la fois. Autrement dit, la structure est soit

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

ou

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

Parce qu'un DWORD se compose d'autant d'octets (4) en deux mots (2 × 2), les alternatives ne sont que deux façons d'adresser (et nommer) les données de la structure entière. Dans notre cas, nous sommes plus intéressés par le mot wProcessorArchitecture plutôt que par l'augmentation dwOemId de wProcessorArchitecture et les mots totalement inintéressants wReserved.

+0

voir mon Edit1 ... – domiSchenk

+0

On dirait que je ne peux pas utiliser GetNativeSystemInfo Coze son pas clairement lisible. Y a-t-il un moyen de le lire hors du registre? je ne sais pas si HKLM \ Sorftware \ Microsoft \ Windows NT \ currentVersion \ BuildLabEx est enregistrer ... – domiSchenk

+0

Il est parfaitement lisible; voir ma mise à jour –

0

Je pense que vous faites comme ça,

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; 
    } 
}