Home > C Programming, C++, VC++, Visual studio > Conditional compilation and conditional inclusion of a resource!

Conditional compilation and conditional inclusion of a resource!

Hope you’ve heard of conditional compilation. Conditional compilation simply means what it says, i.e. compile only when a certain condition is true and it’s only meant for the compiler hence it should only take place during compilation.

We do conditional compilation with help of preprocessor commands. For eg:

void WhoIsNibu()
{
    // 😉
    #ifdef NIBU_IS_A_VERY_GOOD_MVP
         printf( "Nibu is an MVP, Mwhahahaha, Nibu loves Jesus" );
    #else
         printf( "Nibu is still an MVP hehe ;), He loves Jesus" );
    #endif
}

Well now the first printf will only be “compiled” if you define NIBU_IS_A_VERY_GOOD_MVP else the second one will be “compiled”.

Well this was something about conditional compilation, now about including a resource based on a condition. This is mainly for those who are using VC resource editor to include a resource for others you can simply follow normal conditional compilation to decide whether to include or not to include a resource…

In VC resource editor right click on a resource for eg: a menu resource and select properties, now you will find a text field called “Condition”

Condition

See the controls encircled in red.

I’ve entered _DEBUG here, so this menu will only be compiled into the exe when _DEBUG is defined else it won’t be.

Very easy isn’t it. Recently someone asked this in a forum hence thought of posting it here. This is in VC6 but I am sure there is a similar (and better) option in later versions of visual studio too.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: