flavour404
flavour404

Reputation: 6312

Can't access a #defined constant in C

This is a C program that I was using, in the header file I define an offset:

#define LDR_DATA_PATHFILENAME_OFFSET    0x24    // MODULE_ITEM.PathFileName

Later in the program I use it as following:

pImageName = (PUNICODE_STRING)( ((DWORD)(pUserModuleListPtr)) + 
(LDR_DATA_PATHFILENAME_OFFSET-dwOffset));

When inspecting the value of LDR i get an CXX0017: Error: symbol "LDR_DATA_PATHFILENAME_OFFSET" not found. Erm, its defined, it compiles, but yet it can't access the value! What am I doing wrong?

Upvotes: 0

Views: 825

Answers (4)

Igor Krivokon
Igor Krivokon

Reputation: 10275

Are you sure your header file is being included? Easy check - copypaste the #define from the header file to the beginning of your C file.

Double check the #ifndef guards in your header file.

Upvotes: 3

John Deters
John Deters

Reputation: 4391

Are you using an older C compiler? You're using a C++ style comment // instead of the C style comment of /* */. Older C compilers won't recognize the //.

Upvotes: -1

Dan Olson
Dan Olson

Reputation: 23377

Find the option in your compiler to dump preprocessed source so you can see what's really going on. Your symbol may have gotten undefined, or your header isn't included correctly as you expect.

Upvotes: 0

Fabio Vinicius Binder
Fabio Vinicius Binder

Reputation: 13214

I am assuming that you are debugging your application because you said "inspecting": Symbolic constants are substituted by its values at compile time. At runtime you can´t see them anymore.

Upvotes: 7

Related Questions