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
LVL 7
minnirokAsked:
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.

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

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.

Thanks.
0
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.