I am trying to use GetVersionEx() from the Windows API with the OSVERSIONINFOEX structure, but this keeps throwing a warning about an incompatible pointer type:
OSVERSIONINFOEX osInfo;
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx(&osInfo);
printf("%ld\n", osInfo.dwBuildNumber);
full warning:
id.c:31:18: warning: passing argument 1 of 'GetVersionExA' from incompatible pointer type [-Wincompatible-pointer-types]
31 | GetVersionEx(&osInfo);
| ^~~~~~~~
| |
| OSVERSIONINFOEX * {aka OSVERSIONINFOEXA *}
In file included from C:/msys64/mingw64/include/winbase.h:36,
from C:/msys64/mingw64/include/windows.h:70,
from id.c:1:
C:/msys64/mingw64/include/sysinfoapi.h:64:61: note: expected 'LPOSVERSIONINFOA' {aka 'struct _OSVERSIONINFOA *'} but argument is of type 'OSVERSIONINFOEX *' {aka 'OSVERSIONINFOEXA *'}
64 | WINBASEAPI WINBOOL WINAPI GetVersionExA (LPOSVERSIONINFOA lpVersionInformation);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
CodePudding user response:
GetVersionEx() expects an OSVERSIONINFO* pointer, not an OSVERSIONINFOEX* pointer. However, the OSVERSIONINFO* pointer can point at an OSVERSIONINFOEX instance, so you just need to use a typecast, eg:
GetVersionEx((LPOSVERSIONINFO)&osInfo);
