IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

Indication d'OS ?


Sujet :

MFC

  1. #1
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut Indication d'OS ?
    int GetOs()
    {
    OSVERSIONINFO osvi;

    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx( &osvi );

    if( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT )
    return DIJ_OS_WINNT;
    else if( osvi.dwPlatformId == VER_PLATFORM_WIN32s )
    return DIJ_OS_WIN31;
    else if( osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
    {
    if( osvi.dwMinorVersion == 0 )
    return DIJ_OS_WIN95;
    else if( osvi.dwMinorVersion > 0 )
    return DIJ_OS_WIN98;
    }
    return DIJ_OS_INCONNU;
    }

    Bonjour,

    voici une fonction qui me permet de r�cup�rer l'OS sur lequel je suis.
    Cela fonctionne correctement tant que je suis sous Windows 95 - 98 - ou NT, mais cela ne fonctionne pas sous Windows XP.
    En effet, ce programme a �t� cr�� alors que WinXP n'existait pas encore, et j'ai l'impression que le prog. passe dans le code pour Win98.

    Quelqu'un sait il quelle valeur correspond � Windows XP, ou quelle est l'erreur dans ce code ?

    Merci d'avance.

  2. #2
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    salut,
    dans le cas de xp:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    //--------------------------------------------------------------------------------
    BOOL IsWindowsXP()
    {
        OSVERSIONINFOEX osvi;
        BOOL bOsVersionInfoEx;
     
       // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
       //
       // If that fails, try using the OSVERSIONINFO structure.
       ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     
       if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
       {
          // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
          osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
          if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
             return FALSE;
       }
       if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
       {      
             if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                return TRUE;
       }            
       return FALSE; 
    }

  3. #3
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    J'ai utilis� le code qui m'a �t� montr�, mais quand j'utilise le deboggueur, je me rends compte que je passe dans la si pour Windows 98...

    Etrange, non ?

    Du coup, ca me fonctionne pas forc�ment...

    Quelqu'un a une id�e ?

    Merci

  4. #4
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    �a renvoie true pour win98 ?
    �a m'etonne montre moi ton code avec des balises de code cette fois ci !

  5. #5
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    Oui...

  6. #6
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    ma fonction ou ta fonction modifiee ?

  7. #7
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    int GetOs()
    {
    	OSVERSIONINFOEX	osvi;
     
    	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    	if(!GetVersionEx((OSVERSIONINFO *)&osvi))
    	{
    		osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    		GetVersionEx((OSVERSIONINFO *)&osvi);
    	}
     
    	if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
    		return DIJ_OS_WINNT;
    	else if(osvi.dwPlatformId==VER_PLATFORM_WIN32s)
    		return DIJ_OS_WIN31;
    	else if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
    	{
    		if(osvi.dwMinorVersion==0)
    			return DIJ_OS_WIN95;
    		else if(osvi.dwMinorVersion>0)
    			return DIJ_OS_WIN98;
    	}
    	return DIJ_OS_INCONNU;
    }
    Voici ce que j'ai �crit...

  8. #8
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    moi je ferais �a :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    int GetOs()
    {
        OSVERSIONINFOEX osvi;
        BOOL bOsVersionInfoEx;
     
       // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
       //
       // If that fails, try using the OSVERSIONINFO structure.
       ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     
       if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
       {
          // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
          osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
          if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
             return  DIJ_OS_INCONNU;;
       }
       if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
       {      
             if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                return DIJ_OS_WINXP;
          return   DIJ_OS_WINNT;
       }            
      if(osvi.dwPlatformId==VER_PLATFORM_WIN32s) return DIJ_OS_WIN31; 
      if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
      {
        if(osvi.dwMinorVersion==0) return DIJ_OS_WIN95;
        else if(osvi.dwMinorVersion>0) return DIJ_OS_WIN98;
      } 
       return  DIJ_OS_INCONNU;; 
    }

  9. #9
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    Je ne comprends pas.

    J'ai repris exactement la fonction donn�es et je ressorts avec DIJ_OS_WIN98...

    Alors que je suis sous windows XP Professionnal...

  10. #10
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    il y a embrouille je viens de tester �a sur un projet bidon:
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    int GetOs()
    {
        OSVERSIONINFOEX osvi;
        BOOL bOsVersionInfoEx;
     
       // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
       //
       // If that fails, try using the OSVERSIONINFO structure.
       ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     
       if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
       {
          // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
          osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
          if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
             return  -1;
       }
       if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
       {      
             if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                return 4;
          return   3;
       }            
      if(osvi.dwPlatformId==VER_PLATFORM_WIN32s) return 0; 
      if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
      {
        if(osvi.dwMinorVersion==0) return 1;
        else if(osvi.dwMinorVersion>0) return 2;
      } 
       return  -1; 
    }
    �a renvoie bien 4 : xp et je suis xp Pro.
    � mon avis verifies les valeurs de tes defines DIJ_OS_WIN98 etc...

  11. #11
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    Effectivement, j'ai fait le m�me test dans un petit programme, et ca me ressort bien windows XP.

    Mais quand je mets le m�me code dans mon application, �a me ressort Windows 98...

    Il doit y avoir une initialisation quelque part qui me modifie les valeurs de l'OS...
    Je vais chercher.

    Merci pour les infos.

  12. #12
    Membre habitu�
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    10
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 10
    Par d�faut
    J'ai trouv�...

    Le programme principal �tait coch� pour travailler en compatibilit� Win98...
    Donc tout fonctionnait correctement...

    Quand je d�coche cette compatibilit�, le code donn� ci dessus s'ex�cute tout � fait normalement.

    Merci pour le coup de main.

  13. #13
    R�dacteur
    Avatar de farscape
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes C�te d'Azur)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Par d�faut
    effectivement bonjour le piege!,
    tes balises de code ne fonctionnent pas ,parce que dans ton profil le bbcode est desactiv� .

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Foreign-key et indices/index
    Par mesquest dans le forum Outils
    R�ponses: 3
    Dernier message: 21/05/2004, 14h22
  2. [LG]Puissance et Indice
    Par luno2545 dans le forum Langage
    R�ponses: 2
    Dernier message: 08/05/2004, 10h01
  3. [LG]toujours les indices... avec precisions!!!
    Par k_ro dans le forum Langage
    R�ponses: 2
    Dernier message: 25/04/2004, 21h08
  4. [LG]indice en Pascal... merci d'avance
    Par k_ro dans le forum Langage
    R�ponses: 3
    Dernier message: 24/04/2004, 20h58
  5. BDD, r-a-z index et indice primary key ?
    Par lord_paco dans le forum MS SQL Server
    R�ponses: 9
    Dernier message: 11/07/2003, 10h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo