hit counter for tumblr
Real Time Web Analytics


expdef - def file generator

Updated: 2011-10-07 15:10:39
If you found mistake, simply select it
and press Control+Enter

EXPDEF is a small utility that generates module definition file for Windows DLL.


This is a problem to staticaly link your Win32 project in Visual Studio with DLL if your haven't import library for this DLL. Microsoft provides command line tool LIB.EXE that can create such import library if your have corresponding module definition (.DEF) file, but there is no standard ways to create .DEF file.

Overview of DEF file syntax

The basic syntax of .DEF file in part that describes exported functions is listed below.
LIBRARY mylib.dll
    ; entryname[=internalname] [@ordinal [NONAME]] [DATA] [PRIVATE]
    entryname  @ordinal
there are:


Microsoft provides the command line utility DUMPBIN.EXE that helps to obtain the list of exported symbols for the DLL. Sample output from DUMPBIN.EXE is listed below.
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Dump of file mylib.dll

File Type: DLL
    ordinal hint RVA      name

       1994    0 000012A0 ACCESS_DESCRIPTION_free
       2751    1 00001230 ACCESS_DESCRIPTION_it
       1925    2 00001280 ACCESS_DESCRIPTION_new
As you see, output from DUMPBIN.EXE need too much of hand job to create .DEF file.


The format of .DLL (and other PE files) described in WinNT.h from Microsoft SDK and we can write our own utility that reads DLL and generates .DEF.

Using expdef and lib tools

Sample of EXPDEF usage in conjuction with Microsoft LIB tool is listed below. Note: to call LIB tool you need it to be in PATH environment variable. You can set up PATH and other environment to right way by calling vsvars32.bat, which is typicaly in C:\Program Files\Microsoft Visual Studio 8\Common7\Tools directory (for Visual Studio 2005).
>EXPDEF.EXE -p -o mylib.dll >mylib.def
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

   Creating library mylib.lib and object mylib.exp
You also can invoke LIB tool automaticaly from EXPDEF by specifying -l (and -d) command line switches

Overview of expdef command line switches

Your can list all supported command line switches using expdef /? to see help screen in listing above.
Usage: expdef [-v] [-dname] [-l] [-p] [-o] [-u] [-r] [-f] filename.dll
      -v     - verbose output
      -dname - output def file name (stdout used if not taken)
      -l     - invoke LIB tool automaticaly (requires -d option)
      -p     - print ordinals
      -o     - order by ordinals
      -u     - create underscored aliases
      -r     - create ununderscored aliases (remove underscore if present)
      -f     - use filename instead of internal module name
there are switches has next meaning:

Source code

Source code of expdef utility to view it online can be found here.

List of the files to download
Name Last modified Size Hash MD5/SHA1
expdef.exe 2011-09-30 176.0 KB 50548909517f65dc9acc1a4bfbc53cf6 / 6b3f8b1a40b9fb2d855f5d78e73a9585022fb312
expdef.zip 2011-09-30 84.8 KB 5d6d734e916dda6b8e1a7a93e875faa9 / 700a780747772345a84f97328320dae2df3a4750
expdef_src.zip 2011-09-30 2.0 KB 0b2b0c79cbf43153ba64e7d844867507 / 0727db2e6a4b2e42106a96b91d7e6f3843c44ad6