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