• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

translate #defines

Hi,

Is there anyway to convert a #define from a string into it's numeric value:

    "SS_BLACKFRAME"

for instance should be intrepreted as whatever ms defined as its real numeric value:

    "SS_BLACKFRAME"  =  SS_BLACKFRAME  =  0x07L

I'm just trying to write a small interpreter, and I don't want to have a function to translate them like:

    int TranslateDefs(CString str)
    {
        if (str == "SS_BLACKFRAME") {
            return 0x07L;
        }
        // etc...
    }

Thank you
0
minnirok
Asked:
minnirok
  • 2
1 Solution
 
mahesh1402Commented:
whats exactly you are looking for ?
#define is Preprocessor directive that means compile time your values will be changes with whatever you define it as.

MAHESH
0
 
minnirokAuthor Commented:
yeah ms must have this someplace, probably in windows.h or something:

    #define SS_BLACKFRAME 0x07L

Now I'm reading a text file that has this on a line:

    "SS_BLACKFRAME"

I want to be able to store the defined value of SS_BLACKFRAME in a DWORD:

    DWORD dwStyle;

    dwStyle = SomeFunkyThingToTurnTheTextRepresentationIntoTheNumericVal("SS_BLACKFRAME");

Thanks
0
 
jkrCommented:
Use a map:

#include <map>
usinag namespace std;

map<char*,DWORD> mapNameToId;

mapNameToId["SS_BLACKFRAME"] = SS_BLACKFRAME;

or

#define ADD_ENTRY(x) mapNameToId[#x] = x;
//...
ADD_ENTRY(SS_BLACKFRAME);

DWORD SomeFunkyThingToTurnTheTextRepresentationIntoTheNumericVal(char* x) {

    return mapNameToId[x];
}
0
 
minnirokAuthor Commented:
Ok just wanted to see if there was something to already translate. This should work ok though.

Thanks.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now