problem in getting os version in use

This is a discussion on problem in getting os version in use within the Windows Programming forums, part of the Platform Specific Boards category; i made this function today that get os version so far its good but see problem is that i need ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    187

    problem in getting os version in use

    i made this function today that get os version so far its good but see problem is that i need also to get service pack i want a char * return so i cant strcat or calloc or anyother so i used temp var then i concatenate it but it worked inside the function itself but it didnt work when i printed it in main ?? so here is the code
    Code:
    #include <stdio.h>
    #include <windows.h>
    #define DELIT(P,N) P[N]=0
    char *windows[]=
    {
        "windows 7","Windows Xp","Windows 2000","Windows Vista"
    };
    char * GetWindows(char *Cstring,int *BL)
    {
        char *buffer;
        OSVERSIONINFO Str;
        ZeroMemory(&Str, sizeof(OSVERSIONINFO));
        Str.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        GetVersionEx(&Str);
        if(Str.dwMinorVersion)
            switch(Str.dwMajorVersion) {
                case 6:
                    buffer=windows[0];
                    break;
                case 5:
                {
                    int len,len1;
                    Cstring=Str.szCSDVersion;
                    len=strlen(Cstring);
                    len1=strlen(windows[1]);
                    if(len<0)
                        buffer=windows[1];
                    else {
                        char temp[len+1];
                        strcpy(temp,Cstring);
                        DELIT(Cstring,0);
                        buffer=windows[1];
                        strcat(Cstring,buffer);
                        strcat(Cstring,temp);
                        *BL=1;
                    }
    
                }
                break;
            }
        else {
            if(Str.dwMajorVersion==5)
                buffer="Windows 2000";
            else
                buffer="Windows Vista";
        }
    
        return buffer;
    }
    int main(void)
    {
        char *Windowstype;
        int num;
        char ServicePack[50];
        Windowstype=GetWindows(ServicePack,&num);
        if(num)
            puts(ServicePack);
        else
            puts(Windowstype);
        return 0;
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Why not use the safe variant and make both windows version and service pack parameters to be filled in ? What is num for anyway? Note the extra parameters for size, so your function won't write more into the buffer than it should be. It's up to you to implement it that way

    Code:
    void GetWindows( char* version, size_t version_size, char* servicepack, size_t servicepack_size );
    
    int main(void)
    {
        const size_t string_size = 50;
        char version[ string_size ];
        char servicepack[ string_size ];
    
        GetWindows( version, string_size, servicepack, string_size );
    
        puts( version );
        puts( servicepack );
    
        return 0;
    }
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    hey but i want to make it in one i also tried that but it got corrupt 2 the string so i dunno why the hell it corrupt it :S?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. linked list problem
    By kzar in forum C Programming
    Replies: 8
    Last Post: 02-05-2005, 03:16 PM
  3. small reference problem
    By DavidP in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2004, 07:29 PM
  4. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  5. Replies: 5
    Last Post: 12-03-2003, 04:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21