#ifdef...#endif is not working in Resource(.rc) file
-
Hi All, In my MFC project, some Text box should appear in UI for 32 bit builds and that is not appear for 64 bit builds. For this I have added the following piece of code in Resource.h file Resource.h:
#ifndef _WIN64
#define INCLUDE_32_BUILDS 1
#endif#ifdef INCLUDE_32_BUILDS
#define IDC_GS_CMB_TYPE 5176
#endifand the code in the resource file is:
#ifdef INCLUDE_32_BUILDS
LTEXT "Receiver Output Protocol :",IDC_STATIC,16,42,123,8
EDITTEXT IDC_GS_EDIT_TYPE, 150, 42, 84, 85, ES_AUTOHSCROLL | ES_READONLY
#endifI want to show above text box for only 32 bit application and not in 64 bit application I am able to compile the code successfully, but still I am able to see the above text in UI for 64 bit application. I think #ifdef INCLUDE_32_BUILDS is not working properly in resource file. Please let me know how to make sure that the #ifdef INCLUDE_32_BUILDS work and the text box should not appear for 64 bit application? Thanks, Lakshmi.
-
Hi All, In my MFC project, some Text box should appear in UI for 32 bit builds and that is not appear for 64 bit builds. For this I have added the following piece of code in Resource.h file Resource.h:
#ifndef _WIN64
#define INCLUDE_32_BUILDS 1
#endif#ifdef INCLUDE_32_BUILDS
#define IDC_GS_CMB_TYPE 5176
#endifand the code in the resource file is:
#ifdef INCLUDE_32_BUILDS
LTEXT "Receiver Output Protocol :",IDC_STATIC,16,42,123,8
EDITTEXT IDC_GS_EDIT_TYPE, 150, 42, 84, 85, ES_AUTOHSCROLL | ES_READONLY
#endifI want to show above text box for only 32 bit application and not in 64 bit application I am able to compile the code successfully, but still I am able to see the above text in UI for 64 bit application. I think #ifdef INCLUDE_32_BUILDS is not working properly in resource file. Please let me know how to make sure that the #ifdef INCLUDE_32_BUILDS work and the text box should not appear for 64 bit application? Thanks, Lakshmi.
-
Hi All, In my MFC project, some Text box should appear in UI for 32 bit builds and that is not appear for 64 bit builds. For this I have added the following piece of code in Resource.h file Resource.h:
#ifndef _WIN64
#define INCLUDE_32_BUILDS 1
#endif#ifdef INCLUDE_32_BUILDS
#define IDC_GS_CMB_TYPE 5176
#endifand the code in the resource file is:
#ifdef INCLUDE_32_BUILDS
LTEXT "Receiver Output Protocol :",IDC_STATIC,16,42,123,8
EDITTEXT IDC_GS_EDIT_TYPE, 150, 42, 84, 85, ES_AUTOHSCROLL | ES_READONLY
#endifI want to show above text box for only 32 bit application and not in 64 bit application I am able to compile the code successfully, but still I am able to see the above text in UI for 64 bit application. I think #ifdef INCLUDE_32_BUILDS is not working properly in resource file. Please let me know how to make sure that the #ifdef INCLUDE_32_BUILDS work and the text box should not appear for 64 bit application? Thanks, Lakshmi.
Expanding Richards answer the resource compiler does not have access to the standard C preprocessor predefined macros because you haven't included any of the standard headers :-) _WIN64 whilst a standard predefined macro in the C preprocessor is not predefined in the resource compiler. So your #ifdef _WIN64 is failing because _WIN64 doesn't exist to the resource compiler. And trying to do so you usually need to use RC invoke to go around some stuff the header files contain: RC with predefined Macros (Windows)[^] So Resource compiler starts with exactly one macro RC_INVOKED and includes only macros that are included in it's include section. Once upon a time there was an undocumented _WIN32 but I think even that has gone these days. So the more usual trick is to use the build options tab on the resource file to preset a define. On your resource build you have configurations and you can add predefined macros. Config Properties -> Resources -> General In the macros tab add _WIN64 manually to the 64 bit build. Add _WIN32 to the 32 bit build tab.
In vino veritas
-
Expanding Richards answer the resource compiler does not have access to the standard C preprocessor predefined macros because you haven't included any of the standard headers :-) _WIN64 whilst a standard predefined macro in the C preprocessor is not predefined in the resource compiler. So your #ifdef _WIN64 is failing because _WIN64 doesn't exist to the resource compiler. And trying to do so you usually need to use RC invoke to go around some stuff the header files contain: RC with predefined Macros (Windows)[^] So Resource compiler starts with exactly one macro RC_INVOKED and includes only macros that are included in it's include section. Once upon a time there was an undocumented _WIN32 but I think even that has gone these days. So the more usual trick is to use the build options tab on the resource file to preset a define. On your resource build you have configurations and you can add predefined macros. Config Properties -> Resources -> General In the macros tab add _WIN64 manually to the 64 bit build. Add _WIN32 to the 32 bit build tab.
In vino veritas
Thanks Leon. It worked. Thanks, Lakshmi