C++ ifdef WIN32DLL_导出是什么意思?

C++ ifdef WIN32DLL_导出是什么意思?,c++,winapi,dll,C++,Winapi,Dll,我已经创建了一个DLL文件,在头文件中我看到: #ifdef WIN32DLL_EXPORTS 我不明白这意味着什么,以及在哪里/如何设置WIN32DLL_导出 如果我使用: #ifdef WIN32DLL_EXPORTS #define WIN32DLL_API __declspec(dllexport) #else #define WIN32DLL_API __declspec(dllimport) #endif WIN32DLL_API int testSum(void

我已经创建了一个DLL文件,在头文件中我看到:

#ifdef WIN32DLL_EXPORTS
我不明白这意味着什么,以及在哪里/如何设置WIN32DLL_导出

如果我使用:

#ifdef WIN32DLL_EXPORTS
    #define WIN32DLL_API __declspec(dllexport)
#else
    #define WIN32DLL_API __declspec(dllimport)
#endif

WIN32DLL_API int testSum(void);
testSum被认为是uu declspecdlimport。所以我认为我的项目没有设置为WIN32DLL\u导出?如何更改此设置?

您可以:

在项目的属性>配置属性>C/C++>预处理器>预处理器定义中定义WIN32DLL_导出。 如果使用预编译头,例如stdafx.h,则还可以定义WIN32DLL\u导出 这里有一个define语句。
在您引用的行的正上方有一个注释块。读一下

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the WIN32DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// WIN32DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif

-1这甚至没有试图回答这个问题。而且肯定不是公认的答案。