Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #ifdef...#endif is not working in Resource(.rc) file

#ifdef...#endif is not working in Resource(.rc) file

Scheduled Pinned Locked Moved C / C++ / MFC
c++designtutorialquestionlearning
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 12335695
    wrote on last edited by
    #1

    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
    #endif

    and 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
    #endif

    I 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.

    L L 2 Replies Last reply
    0
    • M Member 12335695

      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
      #endif

      and 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
      #endif

      I 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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to ensure that your .rc file has access to that defined value. Either add it via a #included header file, or in your project properties.

      1 Reply Last reply
      0
      • M Member 12335695

        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
        #endif

        and 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
        #endif

        I 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.

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • L leon de boer

          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

          M Offline
          M Offline
          Member 12335695
          wrote on last edited by
          #4

          Thanks Leon. It worked. Thanks, Lakshmi

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups