I'm just looking for a simple, concise explanation of the difference between these two. MSDN doesn't go into a hell of a lot of detail here.
The difference between dllexport and dllimport
dllexportimportvisual-c++
Related Question
- Objective-c – the difference between #import and #include in Objective-C
- DLL and LIB files – what and why
- The use of .exp and what is the difference between .lib and .dll
- C++ – Why is this program erroneously rejected by three C++ compilers
- C++ – What’s the fundamental difference between MFC and ATL
- C++ – Difference between shared objects (.so), static libraries (.a), and DLL’s (.so)
- Node.js – The difference between “require(x)” and “import x”
Best Solution
__declspec( dllexport )
- The class or function so tagged will be exported from the DLL it is built in. If you're building a DLL and you want an API, you'll need to use this or a separate .DEF file that defines the exports (MSDN). This is handy because it keeps the definition in one place, but the .DEF file provides more options.__declspec( dllimport )
- The class or function so tagged will be imported from a DLL. This is not actually required - you need an import library anyway to make the linker happy. But when properly marked withdllimport
, the compiler and linker have enough information to optimize the call; without it, you get normal static linking to a stub function in the import library, which adds unnecessary indirection. ONT1 ONT2