Using the dllimport Procedure

I am trying to write a dll, here is what my header file looks like:

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


DLLIMPORT void HelloWorld (void);


#endif /* _DLL_H_ */

In the .cpp file, I include this header file, and I'm trying to declare a dll import procedure as follows:

DLLIMPORT void HelloWorld ()
{
   MessageBox (0, "Hello World from DLL!n", "Hi", MB_ICONINFORMATION);
}

But the compiler (I have mingw32 on Windows 7 64 bit) continues to give me this error:

E:\Cpp\Sys64\main.cpp|7|error: function 'void HelloWorld()' definition is marked dllimport|
E:\Cpp\Sys64\main.cpp||In function 'void HelloWorld()':|
E:\Cpp\Sys64\main.cpp|7|warning: 'void HelloWorld()' redeclared without dllimport attribute: previous dllimport ignored|
||=== Build finished: 1 errors, 1 warnings ===|

And I don’t understand why.

+5
source share
2 answers

declspec(dllimport)generates entries in the import table of the module module. This import table is used to resolve symbol references during the link. At boot time, these links are committed by the bootloader.

declspec(dllexport)creates entries in the DLL export table of the DLL. Next, you need to implement the characters (functions, variables) that are declared with it.

DLL, BUILDING_DLL. #define, .

+3

, , BUILDING_DLL.

, DLLIMPORT __declspec (dllimport), __declspec (dllexport), . , , .

MinGW, :

-DBUILDING_DLL

#define BUILDING_DLL

. , #define, , -DBUILDING_DLL gcc.

+2

All Articles