BTW, regarding books - I'd rather not recommend a single book, but point you to one IMO more valuable resource: http://www.osronline.com/i
Main Topics
Browse All TopicsI've an existing kernel mode driver. I want to count the number of times it is being loaded and save it some where in the registry.
I've already read many pages from the DDK's help about using ZwXXX and RtlXXX functions, but as my background knowledge is very poor about kernel mode drivers, and I need to do this as soon as possible, I need two things:
1) A piece of code to help me solve this problem.
2) A good book to start learning about kernel mode drivers. (Assume that I know nothing!)
Any help would be highly appreciated.k
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
BTW, regarding books - I'd rather not recommend a single book, but point you to one IMO more valuable resource: http://www.osronline.com/i
Thanks for your comment.
About the code, when I compiling it with WDK 6000, this error message is displayed:
Compiling - hello.c
errors in directory d:\drivers
d:\drivers\hello
d:\drivers\hello.c(131)
d:\drivers\hello.c(131)
d:\drivers\hello.c(131)
d:\drivers\hello.c
ier 'dwVal'
d:\drivers\hello.c(
d:\drivers\hello.c(
d:\drivers\hello.c(203)
d:\drivers\hello.c(203)
header?)
d:\drivers\hello.c
Linking Executable - objchk_wxp_x86\i386\hello.
link : error LNK1181: cannot open input file 'objchk_wxp_x86\i386\hello
BUILD
BUILD: Done
3 files compiled - 10 Errors
1 executable built - 1 Error
*********************
Line
and line 203 is: BOOL DrvSave (DWORD dwVal) {
When compiling, there are some errors:
errors in directory d:\driver2
d:\driver2\drv.c
er>'
d:\driver2\dr
d:\driver2\drv.c(
d:\driver2\drv.c(
d:\driver2\drv.c(36) : error C2059: syntax error : 'type'
d:\driver2\drv.c(108
d:\driver2\drv.c(
d:\driver2\drv.c(108) : error C2059: syntax error : 'type'
Linking Executable - objchk_wxp_x86\i386\hello.
link : error LNK1181: cannot open input file 'objchk_wxp_x86\i386\drv.o
Where line 7,36,108 are the functions declaration.
Sorry for my late reply, still have problems:
Compiling - drv.c
errors in directory d:\driver2
d:\driver2\drv.c
er>'
d:\driver2\dr
d:\driver2\drv.c(
rning int
d:\driver2\drv.c(58) : error C2275: 'ULONG' : illegal use of this type as an exp
ression
d:\driver2\drv.c
'ulNeeded'
d:\driver2\drv.c
d:\driver2\drv.c
pression
d:\driver2\drv.c
'szkvi'
d:\driver2\drv.c(60
d:\driver2\drv.c
d:\driver2\drv.c
'BYTE'
d:\driver2\drv.c(61)
d:\driver2\drv.c
d:\driver2\drv.c(63) : error C4013: 'ZeroMemory' undefined; assuming extern retu
rning int
d:\driver2\drv.c(82) : error C2065: 'delete' : undeclared identifier
d:\driver2\drv.c
d:\driver2\drv.c(84) : error C2146: syntax error : missing ';' before identifier
'BYTE'
d:\driver2\drv.c(84)
d:\driver2\drv.c(101) : error C2059: syntax error : ']'
d:\driver2\drv.c(127) : error C2065: 'LPBYTE' : undeclared identifier
Linking Executable - objchk_wxp_x86\i386\hello.
link : error LNK1181: cannot open input file 'objchk_wxp_x86\i386\drv.o
BUILD: Finish time: Sun Feb 22 13:58:05 2009
BUILD: Done
3 files compiled - 3 Warnings - 20 Errors
1 executable built - 1 Error
Hi,
I tried, still some problems:
errors in directory d:\driver
d:\driver\mrt.cpp
d:\driver\mrt.cpp(89)
Linking Executable - objchk_wxp_x86\i386\mrt.sy
link : error LNK1181: cannot open input file 'objchk_wxp_x86\i386\mrt.o
I changed ZeroMemory to RtlZeroMemory, and new errors:
errors in directory d:\driver
d:\driver\mrt.obj
ator delete(void *)" (??3@YAXPAX@Z) referenced in function "int __stdcall DrvLoa
d(unsigned long *)" (?DrvLoad@@YGHPAK@Z)
d:\dri
erator new(unsigned int)" (??2@YAPAXI@Z) referenced in function "int __stdcall D
rvLoad(unsigned long *)" (?DrvLoad@@YGHPAK@Z)
d:\dri
al symbol _DriverEntry@8 referenced in function _GsDriverEntry@8
d:\driver\
Still having errors:
errors in directory d:\driver
d:\driver\buffero
al symbol _DriverEntry@8 referenced in function _GsDriverEntry@8
d:\driver\
(Notice that in line 106, I changed LPBYTE to PVOID)
ntStatus = ZwSetValueKey (hKey, &ValueName, 0, REG_DWORD, (PVOID) &dwVal, sizeof (DWORD));
If you have a look at DrvLoad(), the return value, bRet first initialized with FALSE, then never assigned a new value. So it always returns FALSE.
This is one problem with that function, there should be some other problems too. (after *pdwVal = (DWORD) pkvi->Data;
I put bRet = TRUE.
The DWORD value is not correct.
About DrvOpenKey() it works well, used it with DrvSaveKey(), it worked and saved any value I passed to it.
Business Accounts
Answer for Membership
by: jkrPosted on 2009-02-14 at 08:59:42ID: 23641437
Basically, you could do it using the following:
Select allOpen in new window