WinDDK how to include custom libraries

Hi there, I am playing with WinDDK 3790.1830 (but if I get a solution for some newer DDK it will probably also work on my version, since I am probably doing something fundamentaly wrong) and was wondering how do you include libraries

My folder structure looks like

|   dirs
|   make.bat
|   sources.miprj
|   tree.txt
|   
+---client
|   |   dirs
|   |   
|   \---uprogram
|           Main.c
|           makefile
|           sources
|           
\---shared
    |   dirs
    |   
    +---components
    |   |   dirs
    |   |   
    |   \---customdebug
    |           cdebug.c
    |           makefile
    |           sources
    |           

dirs is just a standard file listing all the dirs like this

DIRS =  \
        src

customdebug -> sources file looks like

#
# either PROGRAM, DYNLINK, LIBRARY, NOTARGET
#
TARGETTYPE=LIBRARY
WIG=1

!INCLUDE $(MYBUILD)\sources.miprj

#
# Target info
#
TARGETNAME=CustomDebug

#
# target includes
#
INCLUDES= \
	$(MYLIB); 


#
# List sources for target
#
SOURCES= \
    cdebug.c \

cdebug.c looks like this

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif

#include <stdarg.h>
#include <stdio.h>

#include "CustomDebug.h"

void _debugPrint(const char *format, ...) {
    char szBuf[1024];
    DWORD bytes;
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    
    // Check if the console handle is valid
    if (console == INVALID_HANDLE_VALUE) {
        return; // Handle error for invalid console handle
    }

    // Initialize variable arguments
    va_list args;
    va_start(args, format);

    wvsprintfA(szBuf, format, (LPSTR)(&format + 1)); // Use LPSTR for wvsprintfA

    // End variable arguments processing
    va_end(args);

    // Write the formatted string to the console
    WriteConsoleA(console, szBuf, (DWORD)lstrlenA(szBuf), &bytes, NULL);
}

customdebug.h looks like this

#ifndef _CDEBUG_H_
#define _CDEBUG_H_

#include <windows.h>
#include <tchar.h>

#pragma comment(lib, "CustomDebug.lib")


#ifdef __cplusplus
extern "C" {
#endif

#define debugPrint _debugPrint
void _debugPrint(const char *format, ...);

#ifdef __cplusplus
}
#endif


#endif // _CDEBUG_H_

uprogram-> sources file looks like

##
## Target Info
##
## 
## TARGETTYPE: PROGRAM, DYNLINK, LIBRARY, NOTARGET
## UMTYPE:     console, windows
## 
TARGETNAME=HelloWorld
TARGETTYPE=PROGRAM
TARGET_DESTINATION=Binaries
TARGETPATH=obj
TARGETENTRY=main

!INCLUDE $(MYBUILD)\sources.miprj

UMTYPE=console
UMENTRY=main

#USE_ATL=1

#USE_MSVCRT=1
USE_MSVCRT40=1 #Works only with WinDDK: 3790.1830
#USE_NATIVE_EH=1
#USE_RTTI=1
USE_STL=1

#ATL_VER=71
STL_VER=70

##
## Source Files
##
SOURCES=\
    Main.c \
	
#
# Define librarys to link with
#
TARGETLIBS=   \
	$(MYLIB)\CustomDebug.lib \
	$(DEFAULTLIBS)

#
# custom compiler switches
#
#C_DEFINES=$(C_DEFINES) -DCDECL
#USER_C_FLAGS=
	
#
# custom linker switches
#
#LINKER_FLAGS=
#

and sources.miprj looks like this

#
# either PROGRAM, DYNLINK, LIBRARY, NOTARGET
#
TARGETTYPE=NOTARGET
TARGETPATH=obj

#
# target includes
#
INCLUDES=$(INCLUDES); \
		 $(ZONEBUILD)\shared .. \
		 $(ZONEBUILD)\shared\include; \
		 ..\..\include; \

#
# custom compiler switches
#
#C_DEFINES=$(C_DEFINES) -DCDECL
#USER_C_FLAGS=showIncludes

If I understand this properly with !INCLUDE $(MYBUILD)\sources.miprj you tell the compiler to include sources.miprj inside the file

but no matter what I put inside INCLUDES WinDDK still cannot find my custom library

here is the error WinDDK reports

WDK Version: G:\WinDDK\3790.1830
Environment: fre
Architecture (x86/x64): x86
WLH: wlh
Build Step (dirty/clean): dirty
Output Directory: L:\test\game\test_project\src\..\compiled\
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: Using 8 child processes
BUILD: Object root set to: ==> objfre_wnet_x86
BUILD: Compile and Link for i386
BUILD: Examining l:\test\game\test_project\src directory tree for files to compi
le.
BUILD: zonedebug found in shared\components\dirs, is not a subdirectory of l:\te
st\game\test_project\src\shared\components
BUILD: Building generated files in l:\test\game\test_project\src\client\uprogram
 directory
BUILD: zonedebug found in shared\components\dirs, is not a subdirectory of l:\te
st\game\test_project\src\shared\components
BUILD: Compiling (NoSync) l:\test\game\test_project\src\client\uprogram director
y
1>Compiling - main.c for i386
1>errors in directory l:\test\game\test_project\src\client\uprogram
1>client\uprogram\main.c(1) : error C1083: Cannot open include file: 'CustomDebu
g.h': No such file or directory
BUILD: Compiling  l:\test\game\test_project\src\client\uprogram directory
100>Compiling - main.c for i386
100>client\uprogram\main.c(1) : error C1083: Cannot open include file: 'CustomDebug.h': No such file or directory
BUILD: Compile errors: not linking l:\test\game\test_project\src\client\uprogram
 directory
BUILD: Done

    4 files compiled - 2 Errors
Build done, joining all the files in L:\test\game\test_project\src\..\compiled\

If anyone wants here is my make.cmd script I use to build this

@echo off
setlocal enabledelayedexpansion

rem Save MAKEFLAGS environment variable in a temporary variable
set "temp_flags=!MAKEFLAGS!"

rem Set Default Windows Developer Enviroment (uncomment if you want to use Server 2003 Build Enviroment
set "WDK=G:\WinDDK\3790.1830" rem There is a wierd bug, if WServer 2003 Enviroment is used then I have to close cmd.exe and reopen it again, otherwise everything breaks

rem Set default values for arguments
set "arg1=fre"
set "arg2=x86"
set "arg3=wlh"
REM set "BuildStep=clean"
set "BuildStep=dirty"
if not "%4"=="" set "BuildStep=%4"
set "BuildCMDArgs = -czgw"
if "%BuildStep%"=="dirty" (
    set "BuildCMDArgs=-zgw"
) else if "%BuildStep%"=="clean" (
    set "BuildCMDArgs=-czgw"
)
set "OutputDirectory=..\compiled"

rem Define the MYBUILD variable
set "MYBUILD=%CD%\"

rem Check if command-line arguments are provided
if not "%1"=="" set "arg1=%1"
if not "%2"=="" set "arg2=%2"
if not "%3"=="" set "arg3=%3"

if not "%5"=="" set "OutputDirectory=%5"

rem Set MAKEFLAGS to empty
set "MAKEFLAGS="

rem Check if the WDK variable is already set
if not defined WDK (
    rem Check if the default WDK folder exists
    if exist "G:\WinDDK\WDK_6001" (
        set "WDK=G:\WinDDK\WDK_6001"
        set "WDKDIR=!WDK!"
    ) else (
        rem Ask user for the WDK location
        set /p "WDK=Enter WDK location: "
        rem Check if the provided folder exists
        if exist "!WDK!" (
            set "WDKDIR=!WDK!"
        ) else (
            echo Folder does not exist: !WDK!
            goto :end
        )
    )
)

rem Set WDKDIR variable
set "WDKDIR=!WDK!"

rem Call the make tool with the arguments
call :run_make

:end
rem Restore MAKEFLAGS variable
set "MAKEFLAGS=!temp_flags!"

rem Copy the generated files to the output directory
REM %SystemRoot%\System32\xcopy.exe /s /y /i "%current_dir%\*.exe" "%current_dir%\%OutputDirectory%\" 
REM %SystemRoot%\System32\xcopy.exe /s /y /i "%current_dir%\*.dll" "%current_dir%\%OutputDirectory%\" 
echo Build done, joining all the files in %current_dir%\%OutputDirectory%\
mkdir "%current_dir%\%OutputDirectory%" 2>nul
for /r "%current_dir%" %%F in (*.exe) do copy "%%F" "%current_dir%\%OutputDirectory%\" 
for /r "%current_dir%" %%F in (*.dll) do copy "%%F" "%current_dir%\%OutputDirectory%\" 
for /r "%current_dir%" %%F in (*.pdb) do copy "%%F" "%current_dir%\%OutputDirectory%\" 

endlocal
pause
exit /b

:run_make
rem Get the current directory and save it in a variable
set "current_dir=%CD%"

:: Using command line arguments
echo WDK Version: !WDK!
echo Environment: !arg1!
echo Architecture (x86/x64): !arg2!
echo WLH: !arg3!
echo Build Step (dirty/clean): !BuildStep!
echo Output Directory: !current_dir!\!OutputDirectory!\
if /i "!WDK!"=="G:\WinDDK\WDK_6001" (
	call !WDKDIR!\bin\setenv.bat !WDKDIR!\ !arg1! !arg2! !arg3! && cd /d "%current_dir%" && build.exe !BuildCMDArgs!
) else (
	call !WDKDIR!\bin\setenv.bat !WDKDIR!\ && cd /d "%current_dir%" && build.exe !BuildCMDArgs!
	start "" /d "%current_dir%" cmd.exe
)

rem Return to the main script
goto :eof

If you don't want to use my build.cmd script, use this commands

set "MYBUILD=%ProjectDIR%\" 
set "WDKDIR=G:\WinDDK\3790.1830"
call G:\WinDDK\3790.1830\bin\setenv.bat
%ProjectDIR%\build.exe -czgw

where %ProjectDIR% is the root of my project

Not sure what I am doing wrong, why cannot WinDDK find my library? (If I don't include any library, my program is working fine btw)
Is there any print command I can use inside sources, to help me debug my problem?

and here is my complete enviroment with DDK included:

damm links, I wish I could share this

www(dot)mediafire(dot)com(slash)file(slash)cqm87l56e7w53ln(slash)TestProject(dot)zip(slash)file


replace (slash) with /
replace (dot) with .

Hopefully someone can point me into the right direction, because there is very little written on WinDDk on the internet (especialy if you want to use it to build programs not drivers with it) and to come that far, I had to read numerius code snippets from various projects

What's wrong is that you are using 20-year-old tools to build your software. The tools are old enough to drink. Software tools do not age like wine, they age like milk. WHY are you using tools from 2003???

BTW, I don't see "customdebug.h" in your directory list.

This is just an example I build here so I can ilustrate my problem

I have much bigger similar project (with some files missing), that I am trying to recover and rebuild

Of course will update the tools, just wanted to build with the tools the project was originally built with first

File customdebug.h is in folder include (not sure why its missing from my directory tree though, will generate the tree again)

That is a hopeless approach. The toolset migrated a long time ago away from makefiles (with sources and dirs files) to msbuild project files. Nothing you do to fix up your build with that ancient DDK is going to apply to what you need to do for moving to msbuild.

That said, just add your library to TARGETLIBS in your sources file, as in:

TARGETLIBS=$(TARGETLIBS) some-path\yourlib.lib
1 Like

here is my updated tree

|   dirs
|   make.bat
|   sources.miprj
|   
+---client
|   |   dirs
|   |   
|   \---uprogram
|           Main.c
|           makefile
|           sources
|           
\---shared
    |   dirs
    |   
    +---components
    |   |   dirs
    |   |   
    |   \---customdebug
    |           cdebug.c
    |           makefile
    |           sources
    |           
    \---include
            customdebug.h
            

and here is an updated sources.miprj

#
# either PROGRAM, DYNLINK, LIBRARY, NOTARGET
#
TARGETTYPE=NOTARGET
TARGETPATH=obj

#
# target includes
#
INCLUDES=$(INCLUDES); \
		 $(MYBUILD)\shared .. \
		 $(MYBUILD)\shared\include; \
		 ..\..\include; \

#
# custom compiler switches
#
#C_DEFINES=$(C_DEFINES) -DCDECL
#USER_C_FLAGS=showIncludes

I already have inside my client\uprogram\sources

#
# Define librarys to link with
#
TARGETLIBS=   \
	$(MYLIB)\CustomDebug.lib \
	$(DEFAULTLIBS)

is there any print command so I could print value of my $(MYBUILD) or $(MYLIB) or a way to list what compiler includes?
maybe my file locations are not right

PS: I have to add this to sources.miprj, because there is houndreeds of files that include this file (and adding includes to every file is much harder then just add this to one file)

I know this is hopeless, but its easier to first try to build the project with period (what project was build for) correct tools to figure out if I also have to fix some source files, then once I get my project building I will work on updating the tools to something more modern

You're missing two semicolons in your INCLUDES definition:

#
# target includes
#
INCLUDES=$(INCLUDES);\
		 $(MYBUILD)\shared;..;\
		 $(MYBUILD)\shared\include;\
		 ..\..\include
1 Like

progress Main.c is finding customdebug.h, cdebug.c still not finding it

WDK Version: G:\WinDDK\3790.1830
Environment: fre
Architecture (x86/x64): x86
WLH: wlh
Build Step (dirty/clean): dirty
Output Directory: L:\test\game\test_project\src\..\compiled\
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: Using 8 child processes
BUILD: Object root set to: ==> objfre_wnet_x86
BUILD: Compile and Link for i386
BUILD: Examining l:\test\game\test_project\src directory tree for files to compi
le.
BUILD: Building generated files in l:\test\game\test_project\src\shared\componen
ts\customdebug directory
BUILD: Building generated files in l:\test\game\test_project\src\client\uprogram
 directory
BUILD: Compiling (NoSync) l:\test\game\test_project\src\shared\components\custom
debug directory
BUILD: Compiling (NoSync) l:\test\game\test_project\src\client\uprogram director
y
1>Compiling - cdebug.c for i386
1>errors in directory l:\test\game\test_project\src\shared\components\customdebu
g
1>shared\components\customdebug\cdebug.c(8) : error C1083: Cannot open include f
ile: 'CustomDebug.h': No such file or directory
BUILD: Compiling  l:\test\game\test_project\src\shared\components\customdebug di
rectory
100>Compiling - cdebug.c for i386
100>shared\components\customdebug\cdebug.c(8) : error C1083: Cannot open include
 file: 'CustomDebug.h': No such file or directory
BUILD: Compiling  l:\test\game\test_project\src\client\uprogram directory
BUILD: Linking l:\test\game\test_project\src\client\uprogram directory
1>errors in directory l:\test\game\test_project\src\client\uprogram
1>NMAKE : fatal error U1073: don't know how to make 'objfre_wnet_x86\i386\HelloW
orld.'
BUILD: nmake.exe /nologo BUILDMSG=Stop. -i LINKONLY=1 NOPASS0=1 NTTEST= UMTEST=
386=1 failed - rc = 2
BUILD: Done

    4 files compiled - 3 Errors

also inside src\shared\components\customdebug there is a folder named objfre_wnet_x86 created

here is an updated directory tree

|   buildfre_wnet_x86.err
|   buildfre_wnet_x86.log
|   dirs
|   make.bat
|   sources.miprj
|   
+---client
|   |   dirs
|   |   
|   \---uprogram
|       |   Main.c
|       |   makefile
|       |   sources
|       |   
|       \---objfre_wnet_x86
|           |   _objects.mac
|           |   
|           \---i386
|                   main.obj
|                   
\---shared
    |   dirs
    |   
    +---components
    |   |   dirs
    |   |   
    |   \---customdebug
    |       |   cdebug.c
    |       |   makefile
    |       |   sources
    |       |   
    |       \---objfre_wnet_x86
    |           |   _objects.mac
    |           |   
    |           \---i386
    \---include
            customdebug.h

here is updated sources.miprj

#
# either PROGRAM, DYNLINK, LIBRARY, NOTARGET
#
TARGETTYPE=NOTARGET
TARGETPATH=obj

#
# target includes
#
INCLUDES=$(INCLUDES);\
		 $(MYBUILD)\shared\include;..;\

#
# custom compiler switches
#
#C_DEFINES=$(C_DEFINES) -DCDECL
#USER_C_FLAGS=showIncludes

what does ;..; even do?
I saw this in some code samples, but never, knew its purpose

Thanks for helping guys