What is the difference between __declspec( dllimport ) extern "C" AND extern "C" __declspec( dllimport )
extern "C"
and __declspec(dllimport)
are totally orthogonal.
-
extern "C"
means that C linkage should be used for that symbol. I.e. no C++ name mangling will be applied. It also limits functions' interfaces to C-compatible things: built-in types, trivial structs, and pointers. Essentially, it tells the compiler and linker that a symbol should be found in the "C way" rather than the "C++ way".extern "C"
is generally used for either calling C functions from C++ code or creating a C-compatible interface to C++ code. -
__declspec(dllimport)
tells the linker that a symbol will be loaded dynamically at runtime from a DLL.
The two can be combined as well. A function marked extern "C" __declspec(dllimport)
will be dynamically linked and use C-style linkage.