1
votes

I've searched through some Microsoft tutorials and all related stackoverflow threads to find the right answer. None of them is clear enough for me.

This thread still leaves some doubt.

"__declspec( dllexport ) - The class or function so tagged will be exported from the DLL it is built in"

vs.

"__declspec( dllimport ) - The class or function so tagged will be imported from a DLL"

Well, it hardly makes sense, because what does it mean "import from DLL" and "export from DLL". You can either export from and import to something, or import from and export to something.

My understanding is: dllexport is used to specify that I want to load this code to the DLL I'm creating, whereas dllimport is used to tell the compiler that I'd like to make use of code from a DLL.

Is that correct?

2

2 Answers

1
votes

When you want to use something from a dll, you include the good .h file, which will contain __declspec( dllimport ) ( often done with a #define macro for switching accordingly between export and import when we are compiling).

As a consequence you will import FROM the dll which provides this .h file.

On the contrary when you compile this dll, the .h file contains __declspec( dllexport ), telling the compiler/linker to do the job for exporting such part FROM our dll.