__declspec is a Microsoft-specific attribute that allows you to specify storage class information.
(Nitpicker Corner: However, a number of other compiler providers, such as GCC, now support this language extension for compatibility with an installed code base written for Microsoft compilers. Some even provide additional storage class attributes.) Sub>
Two of these storage class attributes that can be specified are dllimport and dllexport . They tell the compiler that the function or object is imported or exported (respectively) from the DLL.
In particular, they define a DLL interface for a client without requiring a module definition file ( .DEF ). Most people find it much easier to use these language extensions than creating DEF files.
For obvious reasons, __declspec(dllimport) and __declspec(dllexport) are usually paired with each other. You use dllexport to indicate the symbol exported from the DLL, and use dllimport to import the exported symbol into another file.
Because of this, and because the same header file is usually used both when compiling a DLL and in client code that consumes the DLL, this is a common template for defining a macro that automatically jumps to the corresponding attribute specifier when compilation time. For example:
#if COMPILING_DLL #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT __declspec(dllimport) #endif
Then check all the characters that should be exported using dllexport .
Presumably, this is what the Q_CORE_EXPORT macro Q_CORE_EXPORT , allowing either Q_DECL_IMPORT or Q_DECL_EXPORT .
Cody Gray Jan 14 '12 at 15:38 2012-01-14 15:38
source share