0

I am migrating a C++ library from *nix to MSVC.

The code has a function declaration named interface(). This function works well on GCC and Clang compilers but when I'm compiling the code using MSVC, it keeps telling me unknown-type unexpected.

After doing some research, I found out that the function name conflicts with a predefined macro of a Windows library in a file named combaseapi.h.
The definition looks like this:

#define interface __STRUCT__

I tried to add #undef interface in the files that were complaining about the error and everything works fine.

However, there are several files that call and have definitions using this function name. I can declare the #undef interface in all of those files but it seems pretty dirty to me.

Is there any way that I can define that line only just once? I've tried to define it in a header file and include it. But the compiler keeps complaining about the function name is unexpected.

  • 1
    Are you using pre-compiled headers for the include of combaseapi.h? I think that could help. There you include the relevant windows headers only once and undefine interface. But would it not be better maybe change the name of the function in the library itself? – RoQuOTriX Aug 29 '22 at 08:47
  • 2
    [`WIN32_LEAN_AND_MEAN`](https://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly) might be an easier solution – Alan Birtles Aug 29 '22 at 08:56

0 Answers0