MakeDef : Intelligent DEF file Generator for Win32 Apps

The tool I want to post is a DEF-file generator for people who want to use import by ordinals in large projects. The problem is that you should manually process the output of the DUMPBIN.EXE or similar utility and then manually edit large DEF-files. Another problem is that you should keep old ordinal numbers untouched to provide backward compatibility with older versions of your DLLs.

This utility uses a DEF-file and a binary module (usually a DLL) on input. If DEF-file does not exists MakeDef creates an empty one, otherwise DEF-file is opened in append-only mode (old contents remain unchanged anyway). MakeDef reads the DEF-file and compares its contents with the DLL's export table. Any differences would be recorded to the end of the DEF file with ordinal values greater than the maximum value used before. It guarantees that the newly added exports would not ever conflict with previous versions of DLL. All added exports have the NONAME attribute to strip them from the export table. It will significantly reduce the size of your DLLs, but you would not able to load such exports using LoadLibrary() function, so be careful.

Another working mode of MakeDef is _import_ table scanning. It's useful in the following situation: you have an EXE (or several EXE modules) and want to export from the DLL only those functions which are really used in the EXE file(s). In this case MakeDef would scan an import table of an EXE file and store any differences in the DEF file, allowing linker to make correct export table in the DLL.

MakeDef is a console mode utility suitable to use in makefiles and batch builds. The utility itself is very little (8704 bytes), only MSVCRT.DLL is required. It returns the various ERRORLEVELs to signal the processing results:

ERRORLEVEL Meaning
0 Ok, but there were no new exports
1 Ok, and there were new exports written to the DEF file
100 Temporary file creation error
101 Incorrect format of the DEF-file
102 Incorrect DLL/EXE name
103 Missing or corrupted DOS header
104 Missing or corrupted PE image header
105 Invalid PE image (internal error while processing)
106 Invalid parameters

The command line syntax is:


>MAKEDEF /DEF:<def_file_name> /IMAGE:<exe_or_dll_name> /IMPORTS:<dll_name>
Where:
  • /DEF specifies the name of the DEF-file to process
  • /IMAGE - the name of binary file to synchronize
  • The optional /IMPORTS parameter turns on import table scanning instead of export table processing (the default mode).
  • The <dll_name> part of the /IMPORTS directive specifies the DLL name, whose exports would be processed.

    Downloads

    Download Tool - 4 Kb


  • Comments

    • Win2000 Problem

      Posted by Legacy on 10/21/2000 12:00am

      Originally posted by: ade

      Crashes on my computer under Windows 2000. Worked fine on
      the same computer when I had Windows98 and WinNt4.0. Can someone ask the author to post the source ? This is a very useful tool.

      Reply
    • This is awesome... Been looking for this for a long time

      Posted by Legacy on 05/01/2000 12:00am

      Originally posted by: Rich Peters

      George,

      Congratulations.

      This is an awesome tool. I have wanted this for three years, but never had the time to write one.

      It significantly lowers application load time for several of my apps.


      One question:

      Do you know how to get rid of the LNK4197 warnings that come from having an export defined via the def file as well as the declspec?

      thanks again.

      Rich Peters

      Reply
    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

    • Agile development principles have gone from something used only by cutting-edge teams to a mainstream approach used by teams large and small. If you're not using agile methods already though, or if you've only been exposed to agile on small projects here and there, you may wonder if agile can ever work in your environment. Read this eBook to learn the fundamentals of agile and how to increase the productivity of your software teams while enabling them to produce higher-quality solutions that better fulfill …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds