avoid #define

Hello Forum,

I have class with the function "GetMessage()".

MyClass* objMyClass;
objMyClass = new MyClass;
objMyClass->GetMessage();

But when I call this function, the compiler (MVS) thinks that it is a macro from WinUser.h:

#define GetMessage GetMessageA

How do I tell the compiler to use the function?

Thank you.
Welp, congrats you've ran into one of the atrocious issues with using macros (It's not your fault, it's Microsoft's fault).

Are you #including <windows.h> (or <winuser.h>) somewhere before you define either your class or your function call? First step would be to avoid #including <windows.h> in that file, unless you have to.

If you can't avoid that, try doing


#ifdef GetMessage
#undef GetMessage
#endif


before any reference to your "GetMessage" function.

See also:
https://stackoverflow.com/questions/2321713/how-do-i-avoid-name-collision-with-macros-defined-in-windows-header-files

If none of that works, you might just need to change your side of the code to conform to Microsoft's code (don't name something as a macro that already exists).
Last edited on
Other ideas..

rename your function if possible.
you can also try a namespace on yours (possibly, the classname:: is good enough?)
you can also add a bogus parameter to yours (int x = 0) to see if that is good enough to allow an overload

probably some other tricks too.
Last edited on
Yes, I need the windows.h stuff.
undefining their stuff doesn't sound desirable. Either I use windows.h or not.
I already have a namespace for my code, but that doesn't seem to matter.

objMyClass->GetMessage(); // Where goes the namespace?
objMyClass->MyClass::GetMessage(); // Doesn't work.

Hmm, seems renaming my function is the best option.

Thanks.

Topic archived. No new replies allowed.