0

I've been searching around the internet and I have no idea why this happens, it's not really an obvious array issue.

Here's the function:

BOOL IsOsCompatible()
{
    BOOL retVal = 0;
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx(&osvi);
    if(osvi.dwMajorVersion == 6)
    {
        if(osvi.dwMinorVersion == 0)
        {
            if(SendErrorM("This program has not been tested on Windows Vista(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
                retVal = 1;
        }
        else if(osvi.dwMinorVersion == 1)
        { 
            retVal = 1;
        }
        else if(osvi.dwMinorVersion == 2)
        {
            if(SendErrorM("This program has not been tested on Windows 8(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
                retVal = 1;
        }
    }
    else
        SendErrorM("Your windows verison is incompatible with the minimum requirements of this application.",NULL);

    return retVal;

}

Any ideas?

Nutterz
  • 42
  • 7

2 Answers2

1

An OSVERSIONINFOEX is larger than an OSVERSIONINFO, so

    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

will write zeroes "outside" (around) osvi.

You want

OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

or (often safer)

OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(osvi));
molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • I couldn't agree more on this, the problem appeared when I tried to clean the code a little and changed `OSVERSIONINFOEX` into his smaller brother... – Nutterz Aug 24 '13 at 17:34
0

The extra X is your problem:

OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

Windows A, W and X suck.

Avoiding Macros:

template <typename T>
inline void zero_memory(T& m) {
    std::memset(&T, 0, sizeof(T));
}
  • Yep, that was the issue indeed, I thought that they would match, but it seems that the EX one includes some more info resulting in a size mismatch, Thank you very much. – Nutterz Aug 24 '13 at 17:30