Building Win32 Apps With Build.exe And The DDK

I had to search for samples when I first started doing this, and as I was starting a new project last night, I thought about getting this to work the first time.

Building Win32 apps is totally straightforward if you read the excellent BUILD utility documentation, but hey, who’s got time for that? So, here’s a basic SOURCES file that gets the job done:

TARGETNAME=poslpd
TARGETTYPE=PROGRAM

TARGETLIBS = $(SDK_LIB_PATH)\winspool.lib \
             $(SDK_LIB_PATH)\ws2_32.lib

MSC_WARNING_LEVEL = /W4 /Wp64 /WX

UMTYPE=windows
UMENTRY=winmain

SOURCES= poslpd.cpp \
         debug.cpp \
         winthread.cpp \
         poslpd.rc

Some notes:

  • You must set TARGETTYPE, UMTYPE, and UMENTRY as above
  • ‘winmain’ is a symbolic name and does not map to the exact entry point name; see the docs for details
  • I always recommend using an MSC_WARNING_LEVEL at least as strong as above: warning level 4, warnings as errors, and warn about 64-bit portability

You may also want to set:

  • USE_MSVCRT=1 – links a shared lib instead of the default static lib
  • USE_NATIVE_EH=1 – turn on C++ EH support
  • USE_STL=1 – turn on to link to the C++ STL library

The little LPD server I wrote compiles down to only 45K, or if you enable MSVCRT, it’s a measly 12K. But that got me thinking: can you do any better than 12K? Hmmm…

3 Replies to “Building Win32 Apps With Build.exe And The DDK”

  1. He he … you came to about the same conclusions I did, at about the same time, it seems; I couldn’t find a way to get build to function correctly without using UMTYPE=console for the simple “Hello, World” app I wrote. I didn’t need to specify anything for UMENTRY (with UMTYPE == console); and, what I ended up using for libraries surprised me a little; however, everything works at this point, so… I would be happy to send it to you if you’re interested.

    BTW – mozilla is choking on your site; I’ve got “http://www.cslimits.net && click on the cheesy “contact me” picture of me on the LHS of the page.

    Thanks,

    Larry

  2. Hi,
    got following errors

    1>k:\scmload\scmload.obj : error LNK2019: unresolved external symbol __imp__fprintf refe
    1>k:\scmload\scmload.obj : error LNK2001: unresolved external symbol __imp___iob
    1>k:\scmload\objchk_win7_x86\i386\scmload.exe : error LNK1120: 3 unresolved externals

    by using this
    USE_NTDLL=1
    USE_INCREMENTAL_LINKING=1
    UMTYPE=console
    TARGETNAME=scmload
    TARGETPATH=obj
    TARGETTYPE=PROGRAM
    SOURCES=scmload.c
    TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
    $(SDK_LIB_PATH)\winspool.lib \
    $(SDK_LIB_PATH)\ws2_32.lib

    MSC_WARNING_LEVEL=
    UMTYPE=windows
    UMENTRY=winmain

Leave a Reply

Your email address will not be published. Required fields are marked *