Tôi cố gắng để viết một dll, đây là cách nhìn tập tin tiêu đề của tôi:Sử dụng dllimport thủ tục
#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_ */
Trong tập tin cpp tôi bao gồm tập tin tiêu đề này, và tôi cố gắng tuyên bố một thủ tục nhập khẩu theo cách này dll :
DLLIMPORT void HelloWorld()
{
MessageBox (0, "Hello World from DLL!n", "Hi", MB_ICONINFORMATION);
}
Nhưng trình biên dịch (tôi đã mingw32 trên windows 7 64 bit) tiếp tục đem lại cho tôi lỗi này:
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 ===|
Và tôi không hiểu tại sao.
Tôi đã hợp nhất hai tài khoản của bạn để bạn có thể chấp nhận câu trả lời ngay bây giờ. –