阻止C预处理器执行特定的宏替换

Vin*_*rle 6 c++ getmessage c-preprocessor

如何告诉预处理器不要替换特定的宏?

具体问题如下:Windows头文件定义GetMessage宏.

我的API的我的C++头文件有一个GetMessage方法.我不想重命名我的方法.但是在Windows上使用API​​时,包括windows.h用GetMessageA替换了我的GetMessage方法调用.

Sho*_*ace 6

你试过做一个吗?

#undef GetMessage

甚至

#ifdef GetMessage
#undef GetMessage
#endif

然后直接调用Windows GetMessageA或GetMessageW,以适当的方式.

你应该知道你是否使用char*for wchar_t8 ..

(感谢don.neufeld)

Brian还说Jus有一些有用的信息,你也可以使用#pragma push_macro/pop_macro来推送和弹出宏定义.如果要覆盖代码块中的宏定义,这非常有用:

#pragma push_macro("GetMessage")
#undef GetMessage

// Your GetMessage usage/definition here

#pragma pop_macro("GetMessage")
Run Code Online (Sandbox Code Playgroud)

我怀疑这是MS特有的功能,所以请记住这一点.