Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell which configuration I'm in?

Status
Not open for further replies.

Vermithrax

Programmer
Joined
Dec 1, 2003
Messages
3
Location
CA
Hi there. :-) This is my first post, and I hope someone can help me with this... Basically, I have a project in Microsoft Visual Studio .NET 2003, and I need the program to know what configuration it's in... IE: When you choose DEBUG or RELEASE from the configuration manager, is there a way for the program to know which configuration it's in? I want to have the program change a variable based on which configuration I'm building... IE:

CString vConfig;
if ( configuration == "Debug" )
vConfig == "Debug";
else if ( configuration == "Custom" )
vConfig == "Custom";
else if ( configuration == "Release" )
vConfig == "Release";
else
vConfig == "Something else";

etc...

Of course, I have no idea how to do the configuration == "debug" or whatever thing, and that's what I need to know how to do. Any ideas? :-)
 
#ifdef _DEBUG
vConfig = "Debug";
#else
vConfig = "Release";
#endif

Matt
 
I have more than just debug and release versions, though... I have release1, release2, etc... With what you show there, I can only tell if it's debug or not, though.
 
Normally you define a symbol in the Preprocessor definitions in the project settings for each configuration. By default, the Win32 Debug configuration usually has _DEBUG defined, and the Win32 Release configuration has NDEBUG defined. If you have multiple configurations you can come up with your own symbols (make sure they are unique) and define a different one in each configuration. For example, you could define MY_RELEASE_CONFIG_1 in your release1 settings, MY_RELEASE_CONFIG_2 in your release2 settings, etc. Then in your code you could use #ifdef preprocessor directives to include code based on those defined symbols.
Code:
#ifdef MY_RELEASE_CONFIG_1
// ... code for release1 only.
#endif // MY_RELEASE_CONFIG_1
or
Code:
#if !defined(MY_DEBUG_CONFIG_2)
// ... code NOT for debug2 configuration.
#endif // !defined(MY_DEBUG_CONFIG_2)
I'm not too familiar with .NET - I use MSVC++ 6.0 - but I would imagine that it would have the same features. There are lots of ways to utilize these preprocessor definitions so I would recommend looking up #ifdef stuff if you aren't familiar with it. The code above is just examples.
 
Awesome. :-) Thanks so much, uolj. :-) Exactly what I needed to know. I've been programming for about 8 years now, but only recently have I moved over to the Windows platform from Linux (still love Linux, just doin' this for a job!), so I'm still not familiar with the intricacies of it all. Thanks again. :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top