Home > Back-end >  Precompiled macros
Precompiled macros

Time:09-25

C + + Tony one, with the teacher's project involves some c + + program, some is not very understand, come to ask,

# ifdef _WINDOWS32
# ifdef PUB_EXPORTS
# define PUB_API __declspec (dllexport)
# the else
# define PUB_API __declspec (dllimport)
# endif
# the else
# define PUB_API
# endif


Want to know that a program is what mean??????? Why don't compile success?? Why will _WINDOWS32 added to the project properties - c/c + + - the preprocessor definition can compile?? Hope great god answer,,,

CodePudding user response:

You can at the beginning of the code file:
# define WINDOWS32
And
# define PUB_EXPORTS
If you have defined above one or two symbols,
# ifdef is set up, you this code # ifdef is nested, and # else, # endif is cooperating with
Your code should be written DLL, declare DLL output function, as long as you at the beginning of the file # define PUB_EXPORTS, it would be # define PUB_API __declspec (dllexport)
Statement call DLL function, no # define PUB_EXPORTS, it would be # define PUB_API __declspec (dllimport)
Such DLL statement function is unified, such as PUB_API int Max (int x, int y)//can be put in a header file, the statement output and declare DLL function call # include the header file, same PUB_API according to different # define replacement,

CodePudding user response:

If there is no # define _WINDOWS32
Will # define PUB_API
It will be replaced with an empty PUB_API
  • Related