.def files C/C++ DLLs

后端 未结 6 1793
我在风中等你
我在风中等你 2020-11-30 04:31

I am not understanding the point of using .def files with DLLs.

It seems that it replaces the need to use explicit exports within your DLL code (ie. explicit __decls

6条回答
  •  囚心锁ツ
    2020-11-30 04:59

    My understanding is that .def files do not actually specifies which all apis need to be exported. It just contains the apis exported and their ordinal numbers. If you want to actually export a particular api, you need to specify __declspec(dllexport) in the definition of the api and __declspec(dllimport) at the declaration.

    The advantage of def file is that, it helps you to maintain the backword compatibility with the already realsed dlls. i.e it maintains the ordinal numbers for apis. Suppose you add a new api in the dll, then the linker looks at your .def file genearate the ordinal number for the ne wapi such that the ordinal numbers for the old apis are intact.

    So, if the client code uses the latest dll, it does not break the existing apis.

提交回复
热议问题