Two things come to my mind whenever I revisit the subject of using Visual Studio’s compiler and linker to build Windows drivers:
-
It is not officially supported. Indeed, the consensus all over the Internet is that the right way to build Windows drivers is to use the compiler, linker and BUILD tool included in the Windows Driver Kit. However, Visual Studio 2008 includes the /DRIVER linker option, which is described as follows:
Use the /DRIVER linker option to build a Windows NT kernel mode driver.What does it do? Why was it included in Visual Studio if using it for building drivers is not recommended? -
It works. I’m almost afraid to say this out loud lest I incur the wrath of the righteous kernel developers, but the truth of the matter is that drivers built with Visual Studio do work. We’ve been building them this way for years at my workplace, the produced binaries have been deployed on hundreds of machines, and there haven’t been any problems. However, I am aware that the absense of evidence is not evidence of absense, and that the lack of any problems so far doesn’t necessary mean that building drivers with VS is safe.
What really bothers me here is the lack of information. There are a few posts over the Internet from people who use VS to build their drivers, which invariably draw the same response – it is not supported, do not do it, integrate WDK with VS by means of a makefile project if you really want to use VS’s IDE. However, I haven’t found a single reply which points out a concrete reason why you shouldn’t build drivers with VS.
So, does anyone know what would happen if you use VS to build your drivers? What could go wrong? Under what circumstances? I know that you have to set all compiler and linker options yourself, and it’s allright, but what happens if I set them wrong? Will the driver fail to compile, or will it fail to link, or If it builds fine will it crash outright or only when the stars align right? Why would it do that, what causes it? Is there any reason to stop building our drivers with VS which has worked like a charm for years, apart from the fact that it is not officially supported? If it is not officially supported, why put the /DRIVER switch in VS?
The reason this is common-sense is because the resulting flaws can be subtle. Most of this has been cargo cult, though … ever since there was an actual problem. And if I remember correctly that would have been before 2005 (i.e. the first DDKs at all containing a compiler). Correct me if I’m wrong.
Generally, I don’t see a lot that speaks against using the VS compiler though. For the the linker you also have to set the proper subsystem value (i.e. none) and so on … it’s just tedious.
However, keep in mind that the WDK compilers and tools are usually ahead of those in the latest VS at any given time. Consider this: what the WDK contains is a close as you can get to what is used to build Windows itself. Hence the preference for the tools from the WDK.
Technically it can be done. But if you post to a newsgroup and mention the fact, don’t be surprised if you first get to hear a lesson on that topic rather than your actual question 😉