Visual Studio: how to use the platform toolkit as a preprocessor directive?

I have two toolkits for the platform: v110 and v110_xp for my project, and depending on the platform I want to include / exclude part of the compiled code.

_MSC_FULL_VER and $(PlatformToolsetVersion) have exactly the same value for both of these platform toolkits. As an alternative, I tried using $(PlatformToolset) as follows:

 _MSC_PLATFORM_TOOLSET=$(PlatformToolset) 

but the problem is that $(PlatformToolset) not numeric. I wonder how I can use this non-numeric value as a preprocessor directive?

After trying a few solutions, I realized that

 _MSC_PLATFORM_TOOLSET='$(PlatformToolset)' 

and then

 #if (_MSC_PLATFORM_TOOLSET=='v110') [Something] #endif 

works fine but

 #if(_MSC_PLATFORM_TOOLSET == 'v110_xp') [SomethingElse] #endif 

results in "too many characters in the character constant" .

In context, see this similar question: Visual Studio: how to programmatically use the C ++ toolkit

+7
c ++ visual-studio-2012 preprocessor-directive
source share
2 answers

Go to project properties -> C/C++ -> Preprocessor and add the following to Preprocessor Definitions :

_MSC_PLATFORM_TOOLSET_$(PlatformToolset)

Then you can write something like this:

 #ifdef _MSC_PLATFORM_TOOLSET_v110 [Something] #endif #ifdef _MSC_PLATFORM_TOOLSET_v110_xp [SomethingElse] #endif 

This works for me in VS2010.

+6
source share

In VS 2012/2013, if you use the backward compatibility toolkit , _USING_V110_SDK71 _ will be available to you. VS2013 will define the same name, regardless of the platform toolkit name, which is v120_xp.

 #if (_MSC_VER >= 1700) && defined(_USING_V110_SDK71_) // working in XP-compatibility mode #endif 
+3
source share

All Articles