0

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

#ifdef WIN32DLL_EXPORTS

我不明白这是什么意思以及我们可以在哪里/如何设置WIN32DLL_EXPORTS

如果我使用:

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

WIN32DLL_API int testSum(void);

testSum被认为是__declspec(dllimport)。所以我认为我的项目没有设置为WIN32DLL_EXPORTS?我怎样才能改变这个?

4

2 回答 2

11

您引用的行上方有一个注释块。阅读。

// 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
于 2013-11-06T14:22:55.743 回答
3

您可以:

  • WIN32DLL_EXPORTS在项目的定义中Properties > Configuration Properties > C/C++ > Preprocessor > Preprocessor定义。
  • 如果您使用预编译的头文件(例如stdafx.h),那么您也可以WIN32DLL_EXPORTS 使用#define语句在那里定义。
于 2013-11-06T14:19:20.487 回答