translate #defines


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


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


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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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:


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

    DWORD dwStyle;

    dwStyle = SomeFunkyThingToTurnTheTextRepresentationIntoTheNumericVal("SS_BLACKFRAME");

Use a map:

#include <map>
usinag namespace std;

map<char*,DWORD> mapNameToId;



#define ADD_ENTRY(x) mapNameToId[#x] = x;

DWORD SomeFunkyThingToTurnTheTextRepresentationIntoTheNumericVal(char* x) {

    return mapNameToId[x];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minnirokAuthor Commented:
Ok just wanted to see if there was something to already translate. This should work ok though.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.