The relationship between dllimport and dllexport

I have a question regarding dllexport, dllimport in C ++ on Windows. Suppose I have some module.cppand module.hthat export functions using dllexport. Suppose that I also have moduleWrapper.cppand moduleWrapper.hthat imports from the function module.cppusing dllimport.

Can someone explain why I can skip the letter #include module.hin mine moduleWrapper.cppand moduleWrapper.h. I cannot understand how the linker knows about the addresses of functions from module.cpp, well in advance for any explanation

+5
source share
1 answer

From what I understand, you have something like this in module.h:

__declspec(dllexport) void f();

Wrapper.cpp:

__declspec(dllimport) void f();

, module.h. , include:

#ifdef PROJECTNAME_EXPORTS // (the default macro in Visual Studio)
#define PROJECTAPI __declspec(dllexport)
#else
#define PROJECTAPI __declspec(dllimport)
#endif

:

PROJECTAPI void f();

, dllexport DLL dllimport , DLL, .

+7

All Articles