module definition file
Hello everyone,
I am using Visual Studio 2005 to develop C++ DLL (in-process COM). There is a setting in Linker --> Input called Module definition file. This setting makes me confused,
1. I have tried that if input a file name (.def), then the generated DLL be larger than the time when we leave the module definition file to empty. Should we leave it empty or non-empty (input a .def file name);
2. What is the function of the module definition file? Should developer write it manually or generated by system.
thanks in advance,
George
[579 byte] By [
George2] at [2007-11-20 11:50:03]

# 1 Re: module definition file
Def file was very important in Win16 world, but currently it's used for export name customization only (well, couple more features as well :D).
Say you have this code:
#include <windows.h>
extern "C" __declspec(dllexport) int __stdcall fooCStd() { return 0; }
__declspec(dllexport) int fooCPlusPlus() { return 0; }
Build this:cl 374.cpp /link /dll /out:374.dll
Then you'll have those two exported this way:
E:\Temp\374>exports 374.dll
ModuleType:
PE executable (DLL)
Subsystem:
Win32 GUI
ModuleName:
374.dll
Exported Info: BaseOfOrdinals = 1
NumberOfNames = 2
NumberOfFunctions = 2
RelVirtAddr Ord Hint ExportedFuncName
0x00001010 1 0 ?fooCPlusPlus@@YAHXZ
0x00001000 2 1 _fooCStd@0
Well, you decedie to get rid of that ugly name manggling - and here you come with def file.
LIBRARY 374.dll
EXPORTS
fooCStd
fooCPlusPlus
Build: E:\Temp\374>cl 374.cpp 374.def /link /dll /out:374.dll
...and see what is exported now:
E:\Temp\374>exports 374.dll
ModuleType:
PE executable (DLL)
Subsystem:
Win32 GUI
ModuleName:
374.dll
Exported Info: BaseOfOrdinals = 1
NumberOfNames = 2
NumberOfFunctions = 2
RelVirtAddr Ord Hint ExportedFuncName
0x00001010 1 0 fooCPlusPlus
0x00001000 2 1 fooCStd
Perfect! you say. :)