1

I'm new to driver development. I've been asked to write a Universal Mode Driver for a simple USB device. I've been reading the book "Developing Drivers with the Windows Driver Foundation." I've also been looking at and trying to understand the code samples that the book refers to. The book shows C++ code and the code examples I have been looking at are in C++. I even had to go brush up on C++ because I haven't looked at it in this century. Using VS 2017, when I create a project from a template, I choose Visual C++ -> Windows Drivers -> WDF -> User Mode Driver (UMDF V2). After the project is created, by all appearances, it is a C project rather than a C++ project. Am I simply confused? Well, the answer to that is Yes but why does it create a project containing files with .c extension as opposed to .cpp when clearly I chose a Visual C++ template? Any insights for a newby device driver?

Dar
  • 383
  • 1
  • 5
  • 16

1 Answers1

2

UMDF 2 was designed to make it easier to port drivers to KMDF eventually. Since C++ can't really be used in kernel mode, UMDF 2 projects are configured for C per default. If you want to use C++ change the compiler settings in the projects properties, but please make sure that no exceptions escape your code.

Swordfish
  • 12,971
  • 3
  • 21
  • 43
  • Actually C++ can be used in kernel mode, provided you care about important driver stuff like page faults. – Michael Chourdakis Oct 18 '18 at 21:48
  • Thanks for the explanation. With the down vote that my question got, I was afraid I was simply going to have to relegate my question to the "dumb question of the year" category. – Dar Oct 18 '18 at 22:02
  • There is a (rather old) whitepaper about using C++ in kernel mode: [kmcode.doc](http://download.microsoft.com/download/5/b/5/5b5bec17-ea71-4653-9539-204a672f11cf/kmcode.doc) (direct download link). – Swordfish Oct 18 '18 at 22:10