Search code examples
c++winapilogicc-preprocessorvisual-studio-2005

Win32 logic block preprocessor shows inactive


I tried to use a library on visual studio in different ways by modify its macros on preprocessor directives. However a logic block inside an #if directive is shown to me inactive as it was comment. Here is the code:

  #if defined EBML_DLL
    #if defined EBML_DLL_EXPORT
      #define EBML_DLL_API __declspec(dllexport)
    #else // EBML_DLL_EXPORT
      #define EBML_DLL_API __declspec(dllimport)
    #endif // EBML_DLL_EXPORT
  #else // EBML_DLL
    #define EBML_DLL_API
  #endif // EBML_DLL

The problems is that visual studio shows the code within if ebml_dll block inactive (as commented). As result, the dll doesn't show the functions in the object browser of VS.

A Hint: if a backslash is added at the end of #if defined EBML_DLL's line, it active the else block only.


Solution

  • There was a bug in older versions of VS about this, but it was just a display issue. VS was not reading the defines correctly (in your case EBML_DLL, etc).

    It could also be that the constants you are using in your preprocessor statements are not correct and the are missing characters (usually the ones the compiler uses have underscores at the beginning and end)

    To really know for sure which one it is, you can add a random string inside the branch the preprocessor is expected to take and see if the code compiles.

    #if defined EBML_DLL
     this_should_not_compile //you should get an error on this line
    #endif 
    

    Hope this helps...