Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42670

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

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?

Upvotes: 3

Views: 6061

Answers (2)

YeenFei
YeenFei

Reputation: 3208

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

Upvotes: 2

theomodsim
theomodsim

Reputation: 69

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

Upvotes: 2

Related Questions