Module-Definition (.def) Files

Switch View :
ScriptFree
Visual C++ Concepts: Building a C/C++ Program
Module-Definition (.def) Files

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.

You can invoke a .def file during the linker phase with the /DEF (Specify Module-Definition File) linker option.

If you are building an .exe file that has no exports, using a .def file will make your output file larger and slower loading.

See the following sections for more information:

See Also

Reference

Linker Options
Frequently Asked Questions on Building

Other Resources

C/C++ Building Reference

Community Content

rogerdpack2
must instruct VC to use it though...
NB that there are basically two ways to export symbols from a DLL: $0you can either declare them as __declspec(dllexport) $0 $0*or* you can enumerate them in the .def file (or mix and match).$0 $0$0 $0 $0Note that just creating a .def file in your project with a matching name to your dll's name is *not* enough.  You must also specify it as the "Module Definition File" to the Linker. See http://betterlogic.com/roger/?p=3112$0

thewayout
To Larry A. Taylor's question
I believe the functions need to have been declared to use the C calling convention.

__declspec(dllexport) and __clrcall are not compatible.

Have a look here: http://msdn.microsoft.com/en-us/library/3y1sfaz2(VS.80).aspx




ltaylor934
Is dll export incompatible with managed code?

I was trying to make a C++ wrapper that would be called by Visual Basic. I wanted the C++ functions to be managed code as well.

When I put __declspec(dllexport) in the function definition, I get this message:

Error 1 error C3395: 'WCoinCreateProblem' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention c:\Documents and Settings\Larry A. Taylor\My Documents\ ... .cpp 124

So is dllexport incompatible with clrcall or what? Am I missing something here?