Windows Notes

Author:

Stefan Eletzhofer

Date:

2012-10-17

Abstract

This chapter includes notes on building and developing on Microsoft Windows.

Building and linking against DLLs

To have the linker create a dll it is enough to tell the linker to do so in the makefile:

dll:
  link /subsystem:console -out:some.dll /debug:none /dll some.obj

Unfortunately, the windows linker does not know how to link against a dll per default. The linker needs a ‘.lib’ file to be able to link a dll. The linker command above would create three files:

  • some.dll

  • some.lib

  • some.exp

To link against the dll, specify the ‘some.lib’ file:

test.exe:
  link /subsystem:console /out:test.exe test.obj some.lib

Creating a lib file manually

The ‘lib’ tool needs in order to create the ‘.lib’ file a ‘.def’ file, which has to be manually created. The ‘dumpbin’ tool can help:

C:> dumpbin /exports some.dll
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file some.dll

File Type: DLL

  Section contains the following exports for nxfs.dll

    00000000 characteristics
    507E6F98 time date stamp Wed Oct 17 10:43:04 2012
        0.00 version
           1 ordinal base
           2 number of functions
           2 number of names

    ordinal hint RVA      name

          1    0 000026C0 some_func
          2    1 00003B10 some_func_1

  Summary

        9000 .data
        3000 .rdata
        2000 .reloc
       1E000 .text

The ‘def’ file ‘some.def’ needs then to look like so:

EXPORTS
some_func
some_func_1