Okay. I've got it - with the help of Microsoft's sample project. You might want to use it yourself actually, if only for a learning experience. Make a new Win32 project and set the type to DLL, and also check "Export Symbols". Then it will create some starting files which illustrate exactly what you have to do.
Basically, in your DLL project, you must declare all free functions and variables, as well as classes to be intended for export from a DLL, by prefacing their names with
__declspec(dllexport)
.
Then, in the project using the DLL, you must declare these symbols as intended to be imported from a DLL, by prefacing their names with
__declspec(dllimport)
.
On the face of it, this means that you can't use the same header file for the DLL project and the DLL user project. However, Microsoft suggest a cunning solution. Instead of writing the declspec out each time, use something like the following:
1 2 3 4 5
|
#ifdef EXPORT
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif
|
Then just put DLLAPI before the names of the symbols to be exported, rather than writing the __declspec yourself. Then, in the DLL project, in the compiler options, define the preprocessor macro EXPORT so that the symbols are marked for export from a DLL. Then in the target project, this macro won't be defined so they'll be marked for input!
Note: __declspec(dllimport), etc might be specific to Visual C++. Okay in MinGW it looks like you can do the same as for Visual C++. On Linux, none of it is necessary apparently, but I haven't actually tried that...