0

I have encountered a problem when I was upgrading a class and need to import an external library.

For example, I am editing a class called CFoo, which has a public method SendMessage(). It works fine until I need to include a library - which contains a macro also named SendMessage(). It causes a complete mess to my current code because all part containing SendMessage() is being replaced by the macro.

I have found a similar question about macro naming collision: How do I avoid name collision with macros defined in Windows header files?

However in my case the public method name can't be changed as it is already released and used in other projects.

Is there a way not to use or include a specific macro, or to specify whether a macro or a method should be used when a function is called?

Thank you very much.

Community
  • 1
  • 1
user3545752
  • 351
  • 1
  • 7
  • 15

2 Answers2

1

If standard compliancy is not a requirement try the push_macro/pop_macro pragmas

#pragma push_macro("SendMessage")
#undef SendMessage
//your stuff
#pragma pop_macro("SendMessage")

It works on MSVC, GCC and CLANG

xvan
  • 4,554
  • 1
  • 22
  • 37
0

I have a vague way to resolve it.

Check using #ifdef..

If so, undefine it using "#undef" before calling your function.

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34