2

Some one told me that if you want to export a library you need use __declspec(dllexport), and when someone uses the library he or she needs to add __declspec(dllimport). But today I found that it is not necessary.

For what reason do we need a __declspec(dllimport)?

GoBusto
  • 4,384
  • 6
  • 25
  • 39
UAG515
  • 23
  • 5

1 Answers1

2

From the documentation:

Using __declspec(dllimport) is optional on function declarations, but the compiler produces more efficient code if you use this keyword. However, you must use __declspec(dllimport) for the importing executable to access the DLL's public data symbols and objects. Note that the users of your DLL still need to link with an import library.

David Heffernan
  • 587,191
  • 41
  • 1,025
  • 1,442
  • Thanks. But what I wonder is that what's the "DLL's public data symbols and objects" meaning. You mean the global or the public part in a class, is that right? – UAG515 Sep 03 '16 at 05:46
  • As well as functions you can export data and classes. That is what is meant by that text. – David Heffernan Sep 03 '16 at 06:16