Bob Kjelgaard schrieb:
Anton (and subsequent posters as well)-
I don’t know about you, but I always write my own code from the scratch and use samples only as a guidance
<<Now that made my day! Nice to know I’m not the only one who thinks that way (I usually go so far as to say that if I have to refer to a code sample to understand something, then the accompanying documentation is potentially deficient).
Not a majority view though, in my own experience.
Excellent view!
May I please add a few comments? Thanks:
Assumption 1:
- Very few people in this world solely earn their living writing
operating systems / OS drivers. (Or training others how to do so.)
Assumption 2:
- You have a relatively simple device
- You need a driver relatively quickly
- You need to be compatible to a lot of OS versions of MS WIndows™
- You can not spend 3-12 months for thoroughly learning and trying
out how to write OS drivers from scratch for all OS versions you have to
support.
Then what do you do?
-
In other domains, e.g. hardware design, it is usually a good start to
use an “application note” or an approved “reference design”. -
For OS drivers a “code sample” from the WDK as a starting point is the
logical choice. -
With something that works at hand now you have time to understand some
of the finer details and intrinsics, and thus can gradually modify or
re-write the sample so it eventually becomes “your” driver. -
But even then it might be desirable to keep the general structure of
the driver close to the sample you used as a starting point. Why?
– With the next incarnation of the OS and its DDK/WDK the sample will
have been adapted to reflect the necessities of the new platform.
– Corrections will have been implemented from the feedback of other
people who used the sample before. -
If the structure remains close, you or your “code mainenance
successor” has a chance to factor in these changes (where necessary)
into “your” driver.
IMO this is not necessarily the “good way” of driver programming.
But it is IMO efficient and acceptable,
- as long as you are careful which samples you use,
- where you get them from (e.g. only WDK/DDK samples),
- and if you document your changes and your rationale somewhere.
(Of course there are enough “oh nice, I can just copy this, twiddle a
bit and it runs somehow”-mentality people in this world. The ‘duct-tape’
types. We are not talking about them.)
Another facet of the problem is of course the question:
“Do I need to become a ‘Ph.D. in Driver Programming’ if what I want to
do is just to send a few bytes to my device and get a few bytes back?”
Yes, I understand that WDM, KMDF and WUDF are a big step towards “make
simple things relatively easily” paradigm.
But until we are completely there, people will_have_to use
templates/samples and modify code. Out of necessity.
Driver programming is a complex issue in a modern world of SMP and
multi-tasking OSs.
Remember Assuption 1? Most people also need to do something else for
their living except driver writing, and don’t have time to learn how to
write PnP, Power Management, WMI, OS-version-abstraction, topics of your choice> code that does not directly contribute to their
device-specific operations.
They actually develop a device. Main focus is NOT a driver - it is an
important prerequisite, but not the main star of the show. There is
hardware, and firmware, possibly an application, and possibly customer
hardware you have to interface to.
And MS Windows™ might not even be the only platform you have to
develop a driver for.
Heresy, I know, but it is known to have happened before!
And this is exactly where frameworks come into the picture - so that you
don’t need to cater for “standard” things that should be handled in a
“standard” way anyway.
Hah! We do_have frameworks, don’t we? What do you say now?
Q: I need to support everything from Win98SE up to Vista64. Can I use WUDF?
A: No, it’s just available for Vista and XP. (For XP and USB only with a
co-installer / update that is ~2.7 MB.)
Q: Can I use KMDF, then?
A: No, it is only available for Vista, XP, Server 2003 and Win2000.
Q: So is there a framework I can use if I need to support WinME and
Win98SE as well?
A: No, you have to use at least WDM.
Q: Will this work on Win98SE as well?
A: Can do, actually quite well, if you buy Walter Oneys WDM programming
book and get WDMSTUB.SYS and USBD98.LIB.
Q: Can I at least use a decent code sample and get something that works
without having to understand every detail of PnP/WMI/PWR from Win98SE
up to Vista64?
A: Yes, you can use the sample code from the WDK. But you should not.
Bob and Martin say you should learn everything about how to write all
finer intrinsics of any OS version you need to support, and write your
own code, using the WDK sample only as a reference/demo.
Q: Well… sounds good, but I am neither a Trainer nor Microsoft Windows
OS Programmer - what do I do if my boss does not want me to?
A: What???
Kindest Regards to you two… SCNR.
-H