0

I have some issue in a driver & I have to troubleshoot it, before that I need to build it. I have no experience in driver. I have the source code & bat file. It might be using WDK 7(I'm not sure) Can anyone guide me in building the driver project with below bat file. Ofcourse I can understand bat file is setting environment variables & calling build.exe

My main questions are:
1. Which WDK i need to install, so that I can specify its path in bat file
2. How to run bat file, do i need to run in visual studio command prompt or how?

if you give some Some general idea on building a driver for a beginner that would be much appreciated. Thanks.

[if you need any info, which i can provide please feel free to ask]

bat fie:

rem @echo off
rem --------------------------------------------------------------------                   
rem SafeBoot Windows NT 32 bit driver build script
rem --------------------------------------------------------------------
set MC_ENV=fre

if "%1%"=="debug" goto dbg
if "%2%"=="debug" goto dbg
if "%3%"=="debug" goto dbg
goto nodbg

:dbg
echo **** DEBUG BUILD ****
set MC_ENV=chk

:nodbg
rem --------------------------------------------------------------------
rem We want the absolute path of this directory, so we use a little utility
rem that creates a batch file that sets this into a environment variable.
rem --------------------------------------------------------------------
..\Translations\Bin\setcd -d DRV_DIR > thisdir.bat
call thisdir
del thisdir.bat

if NOT "%DDK64%"=="" goto x1
set DDK64=D:\Tools\WinDDK\6000
rem set DDK64=C:\WinDDK\6001.18001
:x1

set MSTOOLS=%MSSdk%
set BASEDIR=
set DDKBUILDENV=
set NTDBGFILES=
set DDK_INC_PATH=
set DDK_LIB_DEST=
set DDK_LIB_PATH=
set CRT_INC_PATH=
set CRT_LIB_PATH=
set BUILD_ALT_DIR=

call %DDK64%\bin\setenv %DDK64% %MC_ENV% i386

echo %DRV_DIR%

cd %DRV_DIR%

if NOT "%1"=="/a" goto build
del /q objfre_wlh_x86\i386\*.*
del /q objchk_wlh_x86\i386\*.*
rmdir /Q /S driver32
md driver32

:build
rem set MSC_OPTIMIZATION=/Od
echo Building started...
%DDK64%\bin\x86\build.exe -f -z -E
echo Building completed...
if ERRORLEVEL 1 goto error

rem copy objfre_wlh_x86\i386\McPvDrv.sys driver32\McPvDrv.sys

if "%MC_ENV%"=="chk" (
md ..\..\..\build\Win32\Debug
copy objchk_wlh_x86\i386\McPvDrv.sys ..\..\..\build\Win32\Debug\McPvDrv.sys
echo chk
Raj
  • 263
  • 1
  • 2
  • 14

2 Answers2

2

If you want to build a driver for Windows 7 or newer use Visual Studio 2015 which is integrated with the lastest WDK 10. Building drivers is way easier this way.

If you want to build drivers for Windows XP then you will have to use WDK 7 and use a scripts similar like yours. Wdk 7 has no integration with visual studio. You have to specify source file in a special file called sources. See example drivers from Wdk 7. You can find a good cmd for building such drivers https://www.osronline.com/article.cfm?article=43 This website has the best driver dev tips

If you do not need XP support I highly recommend you go the much much easier way using Visual Studio 2015, windows sdk and windows 10 wdk.

LE: You can also use Visual Studio 2013 which supports integration with WDK 8 and WDK 8.1 but not with WDK 10.

  • @Rado, thanks for that, As of now I got Visual Stduio 2013. and my driver is targetted for Windows 7,8& 10. So what would you suggest for my driver build that's which DDK is better use. – Raj Oct 28 '15 at 10:10
  • 1
    Visual studio 2013 can be integrated with WDK 8 or 8.1 but not with Wdk 10. This way you have the same advantages I said about Visual Studio 2015. Microsoft made driver development easier begining with WDK 8 – Radu Ciocas Oct 28 '15 at 10:17
  • now I'm using VS2013 with DDK 8.1, getting some build error "No Target Architecture" from ntdef.h I guess it is related to windows sdk some how. any suggestions on this error msg, – Raj Oct 28 '15 at 13:11
  • Your C++ preprocessor definitions might be wrong; you should have the symbols _X86_=1;i386=1;STD_CALL; defined in the project settings => c++ => preprocessor definitions or _WIN64;_AMD64_;AMD64 for x64 configurations. Or if this is not the case it might be a incorrect sequence of includes. Are you including ntdef.h directly? What are other headers you are including? – Radu Ciocas Oct 29 '15 at 12:40
0

From your .bat file, it has:

if NOT "%DDK64%"=="" goto x1
set DDK64=D:\Tools\WinDDK\6000
rem set DDK64=C:\WinDDK\6001.18001
:x1

So, it might be looking for that version. If so, here is a page: What is the Microsoft name for WinDDK version 6001.18001?

Also, see https://en.wikipedia.org/wiki/Windows_Driver_Kit Your .bat wants, by default, build 6000 (released: november 29, 2006 for Windows Vista)

You could also try to use the latest one. Here's the link for WDK 10 with download instructions. WDK 7 should be similar: https://msdn.microsoft.com/en-us/library/windows/hardware/ff557573%28v=vs.85%29.aspx so find the right page. This page also has links to other pages that may help answer your other questions.

In any case, you'll need to modify the .bat to point to the correct WinDDK directory by setting the DDK64 variable to point to it.

You can probably install multiple different versions to different directories, but my guess is that the latest will let you build backward compatible versions. So, if you're building for Win7 (e.g.), get the latest DDK for Win7 (see the table in the wiki page).

Community
  • 1
  • 1
Craig Estey
  • 30,627
  • 4
  • 24
  • 48
  • thanks for that, I wan to use DDK8, what files I should expect in the path correspons to "D:\Tools\WinDDK\6000" in DDK8 version. – Raj Oct 28 '15 at 09:58