Sometimes getting null value for windows version and processor type

0

For the most part, the function below works but in rare cases returns a null value:

DWORD WinVerMinor() {
   OSVERSIONINFO osvi;
   ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
   osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   GetVersionEx(&osvi);
   return osvi.dwMinorVersion;
}

Also cpustr below sometimes ends up being null. For example, from an executable app cpustr stores the correct string while the very same code produces a null result in a dll (sometimes).

char cpustr[255]

void proctype()
{
int nBuff[4];
char szMan[13];
char szFeatures[256];
unsigned nProcessorType;

    // Get CPU manufacturer and highest CPUID
    __cpuid(nBuff, 0);
    nHighestFeature = (unsigned)nBuff[0];
    *(int*)&szMan[0] = nBuff[1];
    *(int*)&szMan[4] = nBuff[3];
    *(int*)&szMan[8] = nBuff[2];
    szMan[12] = 0;
    if(strcmp(szMan, "AuthenticAMD") == 0)
        nProcessorType = 0;
    else if(strcmp(szMan, "GenuineIntel") == 0)
        nProcessorType = 1;
    else
        nProcessorType = 2;
    __cpuid(nBuff, 0x80000000);
    nHighestFeatureEx = (unsigned)nBuff[0];
if(nHighestFeatureEx >= 0x80000004)
    {
        char szCPUName[49];
        szCPUName[0] = 0;
        __cpuid((int*)&szCPUName[0], 0x80000002);
        __cpuid((int*)&szCPUName[16], 0x80000003);
        __cpuid((int*)&szCPUName[32], 0x80000004);
        szCPUName[48] = 0;
        for(int i=(int)strlen(szCPUName)-1; i>=0; --i)
        {
            if(szCPUName[i] == ' ')
                szCPUName[i] = '\0';
            else
                break;
        }

        for (int z=0; z < strlen(szCPUName); z++) {
            cpustr[z] = szCPUName[z]; }
    }
return 0;
}

What is the reason for the (sometimes) null values?

c++
c
windows
version
processor
asked on Stack Overflow Jan 27, 2017 by Mirks

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0