Checking visual studio versions using #ifdef #if #ifndef

[sourcecode language=”cpp”]
Note: you should fix the corresponding the #endif. I was lazy to do it.
#if _MSC_VER < 1300 //VC6
// code here
#endif
#if _MSC_VER >= 1300 && _MSC_VER < 1400 //VC7
// code here
#if _MSC_VER >= 1400 && _MSC_VER < 1500 //VC8
// code here
#if _MSC_VER >= 1500 && _MSC_VER < 1600 //VC8
// code here
#if _MSC_VER >= 1600 && _MSC_VER < 1700 //VC10
// code here
Helpful scenarios: Conside you have a library supported only on VC10, use this as shown below :
#if _MSC_VER < 1500 // less than VC9
// Support compiling without shlobj.h from the Vista SDK
#if !defined(IApplicationAssociationRegistration)
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb776332(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/bb776332(v=vs.85).aspx</a>
[/sourcecode]

Leave a Reply

Your email address will not be published.