I have resource file which specifies a dialog. In this dialog I display the app name, version and if it is the 32bit or 64bit version of the program.
#ifdef WIN64
LTEXT "My App, Version 1.2.3.0 (64 bit)", IDC_APPLICATION_TITLE_TEXT, 42, 14, 251, 16, SS_NOPREFIX
#else
LTEXT "My App, Version 1.2.3.0 (32 bit)", IDC_APPLICATION_TITLE_TEXT, 42, 14, 251, 16, SS_NOPREFIX
#endif
This all works great, until I use Visual Studio to edit any of my dialogs, this triggers the resource file to be saved by VS and it strips out my #ifdef leaving only one of the entries (either 32bit or 64bit)
LTEXT "My App, Version 1.2.3.0 (64 bit)", IDC_APPLICATION_TITLE_TEXT, 42, 14, 251, 16, SS_NOPREFIX
My question is, is there a way to prevent VS from striping out the #ifdefs when I edit dialogs in directly in VS, or is there a way to construct the text used in the resource in a way that can be used in the resource.
The only way I know if is to edit the files by hand and NOT use the Resource Editor. Any #define or #ifdef get processed and then removed by the Resource Editor itself, and the "post processed" rc is what gets saved :-\
EDIT: You could stick the compiler directived resources in your .rc2 file, which is NOT processed by the Resource Editor. At least it's "localized" to entries in your RC2 file.
EDIT2: Here's a sample of our VS2019 .RC file for an MFC DLL that utilizes an .RC2 file for non-appstudio sections. Yours should be similar.
Note the two different sections of code for including the .RC2 file. One is for the RC Compiler grammar and one is for the Resource Editor itself (yes, strange).