如何告诉预处理器不要替换特定的宏?
具体问题如下:Windows头文件定义GetMessage宏。
使用API的C++头文件具有GetMessage方法。我不想重命名我的方法。但是,在Windows上使用API时,包括windows.h都将我的GetMessage方法调用替换为GetMessageA。
最佳答案
你试过只是做一个
#undef GetMessage
or even
#ifdef GetMessage #undef GetMessage #endif
and then calling the windows GetMessageA or GetMessageW directly, whichever is appropriate.
you should know if you are using char* for wchar_t8..
(thanks don.neufeld)
Brian also says thatJus some useful info, you can also use the #pragma push_macro/pop_macro to push and pop macro definitions. This is great if you want to override a macro definition in a block of code:
#pragma push_macro("GetMessage")
#undef GetMessage
// Your GetMessage usage/definition here
#pragma pop_macro("GetMessage")
我怀疑这是MS特有的功能,因此请记住这一点。
关于c++ - 防止C预处理程序执行特定的宏替换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/291603/