3

I am playing with DLLs to get a better understanding of them. So I created a simple dll (with load-time dynamic linking) which has functions to Add, Sub and Mul. In the header file for the dll I used __declspec(dllexport) for the function declaration.

For the executable, I added the .lib created after compiling the dll to the properties (for linking). After that I directly called the function Add without using __declspec(dllimport). The program worked. I then changed the function calling to __declspec(dllimport) (Add) and the program worked again.

I am not able to understand what the need of __declspec(dllimport) is? I have not yet coded a run-time linking DLL but from the examples I have seen, dllimport is not needed in that case as well.

Thanks for your assistance.

GSerg
  • 76,472
  • 17
  • 159
  • 346
Harsha
  • 263
  • 1
  • 3
  • 14
  • Thanks @GSerg for editing the code part, will take care in future. – Harsha Jul 19 '12 at 11:57
  • 1
    possible duplicate of [Why/when is __declspec( dllimport ) not needed?](http://stackoverflow.com/questions/4489441/why-when-is-declspec-dllimport-not-needed) – Hans Passant Jul 19 '12 at 12:58
  • @HansPassant yes this is, I could not find the answer earlier. Apologies. Thanks for the pointer – Harsha Jul 20 '12 at 02:50

0 Answers0