Export function from a DLL - Use DEF file or dllexport?

白昼怎懂夜的黑 提交于 2020-01-24 11:08:28

问题


Module-definition (.def) files provide the linker with information about exports, attributes, and other information about the program to be linked. A .def file is most useful when building a DLL. Because there are linker options that can be used instead of module-definition statements, .def files are generally not necessary. You can also use __declspec(dllexport) as a way to specify exported functions.

http://msdn.microsoft.com/en-us/library/28d6s79h%28VS.80%29.aspx

I was wondering, should we prefer .def way? or dllexport way?


回答1:


Module-definition (.def) files provide us with more flexibility to define how data going to be exported.

For example, function exported can be anonymous (identified by ordinal) which prevent people without the declaration information from using it.

It can also ddo function forwarding/redirection as stated below :
http://msdn.microsoft.com/en-us/library/hyx1zcd3(v=VS.80).aspx




回答2:


If you plan on users using your DLL in Visual Basic (not VB.NET), then you may want to opt for using the .DEF file. Visual Basic requires that functions use the stdcall calling convention, and exported stdcall function names are decorated with underscores (_). You can override this function name decoration by explicitly specifying the function name in the .DEF file.

For more information: http://msdn.microsoft.com/en-us/library/dt232c9t%28VS.90%29.aspx



来源:https://stackoverflow.com/questions/3314941/export-function-from-a-dll-use-def-file-or-dllexport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!