0

I always need to copy this line to my source files.

#import "C:\Program Files (x86)\Common Files\system\ado\msado15.dll" no_namespace rename("EOF","EndOfFile")

Now, I want to define it as a macro, such as,

#define IMPORT_MSADO15 #import "C:\Program Files (x86)\Common Files\system\ado\msado15.dll" no_namespace rename("EOF","EndOfFile")

But it doesn't work, since # in macro is an escape code.

Zhang
  • 3,030
  • 2
  • 14
  • 31
  • Possible duplicate of [Can a C macro definition refer to other macros?](https://stackoverflow.com/questions/7972785/can-a-c-macro-definition-refer-to-other-macros) – DYZ Feb 15 '18 at 02:05
  • In brief: a macro definition cannot include further preprocessor directives, because the preprocessor is executed only once (unless you execute it manually as `cpp` several times). – DYZ Feb 15 '18 at 02:06
  • 1
    Fyi, put that line (the first one), but with the added attribute `no_implementation`, in your `stdafx.h`. Then, do it again in `stdafx.cpp` (after the include-list), but use the attribute `implementation_only` instead. That should put in within reach of every source file participating in your likely precompiled header layout, and stop you from having to "copy this line to my source files". You get all the comdef and comutil interaction, the smart pointers, etc, and never have to touch this again. Unrelated, I think you're nuts for not keeping the ADODB namespace. – WhozCraig Feb 15 '18 at 02:08
  • @DyZ according to that reasoning a macro cannot expand to another macro – user253751 Feb 15 '18 at 02:43
  • @immibis A macro can expand to another macro, but that other macro won't expand. Try `#define FOO #define BAR 1` and then `FOO` on the next line, followed by `BAR` on yet another line. It will remain a `BAR`, not expand to `1`. – DYZ Feb 15 '18 at 02:46
  • @DyZ Try `#define FOO BAR` followed by `#define BAR 1` followed by `FOO`. It will expand to `1`. If you are not familiar with the preprocessor's rules, there is no reason to suppose this should be the case, because the preprocessor only runs once. – user253751 Feb 15 '18 at 03:09
  • @immibis We are talking about different things. Your macros do not have cpp directives. Mine and the OP's, do. – DYZ Feb 15 '18 at 03:30
  • @DyZ you previously implied that things are unable to expand recursively because the preprocessor only runs once. (Would you ever expect there's a difference between expanding a macro into another macro, and expanding a macro into a directive, unless you had previously learned that fact?) – user253751 Feb 15 '18 at 03:50
  • accrual problem here is invalid configuration of the project. You supposed to define in project file list of paths where library header files are located. – Marek R Feb 15 '18 at 05:24

0 Answers0