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

    • The first phase of API management was about realizing the business value of APIs. This next wave of API management enables the hyper-connected enterprise to drive and scale their businesses as API models become more complex and sophisticated. Today, real world product launches begin with an API program and strategy in mind. This API-first approach to development will only continue to increase, driven by an increasingly interconnected web of devices, organizations, and people. To support this rapid growth, …

    • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds