The dllexport and dllimport Attributes

The dllexport and dllimport storage-class modifiers export and import functions, data, and objects to and from a DLL. These modifiers, or attributes, explicitly define the DLL’s interface to its client, which can be the executable file or another DLL. Declaring functions as dllexport eliminates the need for a module-definition (.DEF) file, at least with respect to the specification of exported functions. Note that dllexport replaces the __export keyword.

The declaration of dllexport and dllimport uses extended attribute syntax:

__declspec( dllexport ) void func();

Alternatively, to make your code more readable, you can use macro definitions:

#define DllImport   __declspec( dllimport )
#define DllExport   __declspec( dllexport )

DllExport void func();
DllExport int i = 10;
DllImport int j;
DllExport int n;