If you declare a function or object with the dllexport attribute, its definition must appear in some module of the same program. Otherwise, a linker error is generated.
__declspec( dllimport ) int i;
__declspec( dllexport ) int i; // Warning; inconsistent;
// dllexport takes precedence.
__declspec( dllimport ) void func1( void );
__declspec( dllimport ) int i;
int *pi = &i; // Error in C
static void ( *pf )( void ) = &func1; // Address of thunk in C,
// function in C++
void func2()
{
static int *pi = &i; // Error in C
static void ( *pf )( void ) = &func1; // Address of thunk in C,
// function in C++
}
However, because a program that includes the dllexport attribute in the declaration of an object must provide the definition for that object somewhere in the program, you can initialize a global or local static function pointer with the address of a dllexport function. Similarly, you can initialize a global or local static data pointer with the address of a dllexport data object. For example, the following code does not generate errors in C or C++:
__declspec( dllexport ) void func1( void );
__declspec( dllexport ) int i;
int *pi = &i; // Okay
static void ( *pf )( void ) = &func1; // Okay
void func2()
{
static int *pi = &i; // Okay
static void ( *pf )( void ) = &func1; // Okay
}