locked
Define STRINGTABLE resource with enum RRS feed

  • Question

  • I have a large list of defines used to identify text, which is actually located in STRINGTABLE resource.  I also have some procedures that accept the define and emit the text in some way.

    For instance:

    // located in an err.h file
    #define message1 1

    #define message2 2 ...
    void Popup(int x);

    // located in .rc file
    #include err.h
    STRINGTABLE

    BEGIN
      message1, "Text 1"
      message2, "Text 2"
      ...
    END

    It works fine, but I tried to make the code more object oriented by putting the defines into an enum and changing the procedures that use them.

    For instance:

    typedef enum{message1 = 1, message2 ...}RCID;
    void Popup(RCID x);

    Unfortunately trying to compile the RC file with the STRINGTABLE results in 'undefined' error messages.

    I guess I can understand why the RC compiler can't handle this, but it seems there should be a better to do some type checking on calls to the message procedures.


    TOM

    Tuesday, June 26, 2012 4:53 PM

Answers

  • On 6/26/2012 12:53 PM, ncitom wrote:

    I have a large list of defines used to identify text, which is actually located in STRINGTABLE resource.  I also have some procedures that accept the define and emit the text in some way.

    For instance:

    / located in an err.h file
    #define message1 1/
    /#define message2 2 ...
    //void Popup(int x);/

    /// located in .rc file
    #include err.h
    STRINGTABLE/
    /BEGIN/
    /  message1, "Text 1"/
    /  message2, "Text 2"/
    /  .../
    /END/

    It works fine, but I tried to make the code more object oriented by putting the defines into an enum and changing the procedures that use them.

    For instance:

    /typedef enum{message1 = 1, message2 ...}RCID;
    void Popup(RCID x);/

    Unfortunately trying to compile the RC file with the STRINGTABLE results in 'undefined' error messages.
    I guess I can understand why the RC compiler can't handle this, but it seems there should be a better to do some type checking on calls to the message procedures.

    Something like this perhaps:

    #define MESSAGE1_ID 1
    #define MESSAGE2_ID 2
    
    #ifndef RC_INVOKED
    enum {message1 == MESSAGE1_ID, message2 == MESSAGE2_ID};
    #endif

    Another possible trick, avoiding some duplication:

    #ifdef RC_INVOKED
        #define MESSAGE_ENTRY(name, id, text) \
        id, text
    #else
        #define MESSAGE_ENTRY(name, id, text) \
        name = id,
    #endif
    
    #ifdef RC_INVOKED
    STRINGTABLE
    BEGIN
    #else
    enum RCID {
    #endif
    
    MESSAGE_ENTRY(message1, 1, "Text 1")
    MESSAGE_ENTRY(message2, 2, "Text 2")
    
    #ifdef RC_INVOKED
    END
    #else
    LastMessage};
    #endif

    Igor Tandetnik

    Tuesday, June 26, 2012 7:31 PM
  • Thanks Igor,

    I kind of like your second solution.


    TOM

    • Marked as answer by ncitom Wednesday, June 27, 2012 11:10 AM
    Wednesday, June 27, 2012 11:10 AM

All replies

  • On 6/26/2012 12:53 PM, ncitom wrote:

    I have a large list of defines used to identify text, which is actually located in STRINGTABLE resource.  I also have some procedures that accept the define and emit the text in some way.

    For instance:

    / located in an err.h file
    #define message1 1/
    /#define message2 2 ...
    //void Popup(int x);/

    /// located in .rc file
    #include err.h
    STRINGTABLE/
    /BEGIN/
    /  message1, "Text 1"/
    /  message2, "Text 2"/
    /  .../
    /END/

    It works fine, but I tried to make the code more object oriented by putting the defines into an enum and changing the procedures that use them.

    For instance:

    /typedef enum{message1 = 1, message2 ...}RCID;
    void Popup(RCID x);/

    Unfortunately trying to compile the RC file with the STRINGTABLE results in 'undefined' error messages.
    I guess I can understand why the RC compiler can't handle this, but it seems there should be a better to do some type checking on calls to the message procedures.

    Something like this perhaps:

    #define MESSAGE1_ID 1
    #define MESSAGE2_ID 2
    
    #ifndef RC_INVOKED
    enum {message1 == MESSAGE1_ID, message2 == MESSAGE2_ID};
    #endif

    Another possible trick, avoiding some duplication:

    #ifdef RC_INVOKED
        #define MESSAGE_ENTRY(name, id, text) \
        id, text
    #else
        #define MESSAGE_ENTRY(name, id, text) \
        name = id,
    #endif
    
    #ifdef RC_INVOKED
    STRINGTABLE
    BEGIN
    #else
    enum RCID {
    #endif
    
    MESSAGE_ENTRY(message1, 1, "Text 1")
    MESSAGE_ENTRY(message2, 2, "Text 2")
    
    #ifdef RC_INVOKED
    END
    #else
    LastMessage};
    #endif

    Igor Tandetnik

    Tuesday, June 26, 2012 7:31 PM
  • Thanks Igor,

    I kind of like your second solution.


    TOM

    • Marked as answer by ncitom Wednesday, June 27, 2012 11:10 AM
    Wednesday, June 27, 2012 11:10 AM