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