To answer this question we have to revisit the meaning of these keywords. MS VC++ compiler treats any variable/function with __declspec(dllimport) as imported from other modules. For __declspec(dllexport) the mechanism is reversed. With __declspec(dllexport) keyword compiler treats this symbol to be exported from the module and thus external modules can import this symbol.

Example:
Suppose I am writing a math library which has a function add(). Now I want my add() function to export from my module or rather expose this to outside world.
In my math.c I shall write like this

/*math.c*/
int __declspec(dllexport) add(int a, int b)
{
  return (a + b);
}
Now when I shall build, I shall get the binary math.dll as well as math.lib.
After getting this files I shall create by math package with three files and they are
  1. Binary i.e. math.dll
  2. Import Library i.e. math.lib
  3. math interface header i.e. math.h
In my math.h I shall declare my add() interface as
/*math.h*/
int __declspec(dllimport) add(int a, int b);
Any application which will use my math package will include my header at compile time. Also math.lib is needed at linking time. Finally when running the application math.dll will be needed.

About our authors: Team EQA

You have viewed 1 page out of 27. Your DLL learning is 0.00% complete. Login to check your learning progress.

#