Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows 8.1 and latter] warning C4996: deprecated GetVersionExA #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

matlo607
Copy link
Contributor

I would like to get rid of C4996 ([Microsoft] GetVersionEx function) triggered by VS2013, VS2015 and VS2017.

StackWalker.cpp
     3>C:\Users\mlongo\.conan\data\StackWalker\master\murex\testing\build\e0a02d496bbb652b6295152dfce0d3937acc0b56\StackWalker-master\Main\StackWalker\StackWalker.cpp(1045): warning C4127: conditional expression is constant [C:\Users\mlongo\.conan\data\StackWalker\mas
       ter\murex\testing\build\e0a02d496bbb652b6295152dfce0d3937acc0b56\StackWalker.vcxproj]
     3>C:\Users\mlongo\.conan\data\StackWalker\master\murex\testing\build\e0a02d496bbb652b6295152dfce0d3937acc0b56\StackWalker-master\Main\StackWalker\StackWalker.cpp(1407): warning C4996: 'GetVersionExA': was declared deprecated [C:\Users\mlongo\.conan\data\StackWalk
       er\master\murex\testing\build\e0a02d496bbb652b6295152dfce0d3937acc0b56\StackWalker.vcxproj]

I replaced GetVersionEx by RtlGetVersion (available starting with Windows 2000). It should not create compatibility issues.
It displays now a good value: OS-Version: 10.0.16299 0x100-0x1 vs GetVersionExA OS-Version: 6.2.9200 () 0x100-0x1
I am not sure about using _MSC_VER to choose this piece of code instead of the old one. The best may be to check NT version at build time. Any idea ?
Do you think this fix could trigger an issue on old Windows versions ?

@JochenKalmbach
Copy link
Owner

We should check for _WIN32_WINNT > _WIN32_WINNT_NT4 to use the new function… are you sure this is available from w2k? I do not believe this…. it is in w2k, but only in the kernel lib… so you need to have rtlver.lib... this lib is not available in all VS versions…
See also: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-rtlisntddiversionavailable
I assume it is available for Windows Vista and later... so we should check _WIN32_WINNT >= 0x0600 (_WIN32_WINNT_VISTA)

See: https://docs.microsoft.com/de-de/cpp/porting/modifying-winver-and-win32-winnt

@matlo607
Copy link
Contributor Author

I am sorry, I am a unix guy so not very familiar with Windows development. The situation is a bit confusing for me.
From what I can read in the doc, OSVERSIONINFOEXA, OSVERSIONINFOA and GetVersionExA() are available since Windows 2000. Why do we have 2 cases (_MSC_VER <= 1200 and _MSC_VER < 1800) with GetVersionExA() ?

it is in w2k, but only in the kernel lib… so you need to have rtlver.lib... this lib is not available in all VS versions…
See also: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-rtlisntddiversionavailable

A kernel lib should be available with the OS and not bundled within VS. Am I wrong ?
Please could you explain me in more details ?

@matlo607 matlo607 force-pushed the vs2013-warning-C4996-GetVersionExA branch from 1f89fda to cf33163 Compare July 12, 2018 15:22
@JochenKalmbach
Copy link
Owner

It is a little bit complicated....
Windows OS contains the function since w2k.
But tge win32 API (which is a subsystem in windows) does not provide an API (or better/ LIB) dor accessing it....
The function was only available if you have installed the WDK (Windows Driver Kit). Then you have to reference a special lib (rtlver.lib). This lib is not part of your VS installation.
Starting with Windows Vista they asded this function to the Win32 SDK; there is no need for rtlver.lib again. And the SDK is installed wirh VS.
This is the reason why I would suggest to use both variant dependend of the target system of the compiling application. This is defined by the above macro. If the macro is equal or same as Windows Viata, we can assume that the VS and SDK contains the function in the Win32 SDK.
We should never try to use the rtlver.lib file because this is normally not installed...

1 similar comment
@JochenKalmbach
Copy link
Owner

It is a little bit complicated....
Windows OS contains the function since w2k.
But tge win32 API (which is a subsystem in windows) does not provide an API (or better/ LIB) dor accessing it....
The function was only available if you have installed the WDK (Windows Driver Kit). Then you have to reference a special lib (rtlver.lib). This lib is not part of your VS installation.
Starting with Windows Vista they asded this function to the Win32 SDK; there is no need for rtlver.lib again. And the SDK is installed wirh VS.
This is the reason why I would suggest to use both variant dependend of the target system of the compiling application. This is defined by the above macro. If the macro is equal or same as Windows Viata, we can assume that the VS and SDK contains the function in the Win32 SDK.
We should never try to use the rtlver.lib file because this is normally not installed...

@matlo607
Copy link
Contributor Author

Ok so first question, is SDKDDKVer.h available in all versions of Visual Studio ?
Here are the pages summing up the platforms supported by:

All of them support XP. If I compile the code with XP SDK and VS2017, it should be okay using RtlGetVersion, isn't it ?

@JochenKalmbach
Copy link
Owner

We just use
_WIN32_WINNT >= 0x0600
which is available in all compuler settings starting from NT... so no need to include anything special

Main/StackWalker/StackWalker.cpp Outdated Show resolved Hide resolved
Main/StackWalker/StackWalker.cpp Outdated Show resolved Hide resolved
Main/StackWalker/StackWalker.cpp Outdated Show resolved Hide resolved
@matlo607 matlo607 force-pushed the vs2013-warning-C4996-GetVersionExA branch 4 times, most recently from c78a6ec to a7127f2 Compare July 13, 2018 12:11
@matlo607 matlo607 force-pushed the vs2013-warning-C4996-GetVersionExA branch from a7127f2 to 3110f60 Compare August 6, 2018 10:51
@matlo607
Copy link
Contributor Author

matlo607 commented Aug 12, 2018

@JochenKalmbach, could you please review again this PR ?

@matlo607
Copy link
Contributor Author

Hello @JochenKalmbach,
Any comment about this PR ?

@JochenKalmbach
Copy link
Owner

You now introduce STL code into project, which was not used until now… I am not happy about these changes...

@matlo607
Copy link
Contributor Author

Hello @JochenKalmbach,
I will remove the last commit using STL.
Why do you want not to use STL whereas C++ is already used in the project and the only platform targeted by the project is Windows (where STL is supported) ?

@matlo607
Copy link
Contributor Author

Hello @JochenKalmbach,
Please could you tell me why introducing STL code into the project is bothering you ?

@JochenKalmbach
Copy link
Owner

It is just a feeling… adding the dependency to STL for a little function… 100% of the code currently is not dependend to STL... now for 1% of the code we add this dependency… it is just a feeling...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants