To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

Driver Development for Windows 64-bit

Driver Development for Windows 64-bit

Mar 24 2007

Questions concerned with the release of drivers for 64-bit versions of Windows are considered in this article. Some typical problems and the ways of their solutions are listed in the article as well as tools which simplify the process of drivers developing.


The output of the first version of the Windows operating system for 64-bit AMD64 processors in 2005 posed a new problem for driver developers. This problem was the opportunity to release drivers for 32-bit and 64-bit systems. At that time many manufacturers turned out not to be ready for supporting of drivers for two systems, that's why many devices didn't get any renewed drivers. At that time this was excusable because 64-bit systems were a novelty and only few users could appreciate them. However, the situation changed greatly when Windows Vista x64 was released. Now even home users want to have a 64-bit system and the developers have to think about the release of 64-bit versions of drivers without fail.

First of all there arises a question. "Do the 64-bit drivers for 64-bit versions of Windows have to be developed?" And there comes a definite answer: "They do". The point is that it is impossible to use 32-bit drivers with a 64-bit system in the kernel mode.

While developing drivers for 64-bit system one should take into consideration some peculiarities. The neglect of them can possibly lead to vain attempts to understand why some things do not function as they used to. MSDN covers the question of 64-bit drivers development thoroughly enough, but sometimes the information turns out to be too uncoordinated. That's why this article gives a survey of main problems and directions for the further study of this question.

Main Theses

While developing drivers for Win64 it is desirable to use the same source code that was used for Win32. The differences in code should be brought to separate code sections under conditional compilation.

  • Let's enumerate some important theses which are concerned with 64-bit drivers.
  • The support of DMA (Direct Memory Access).The inclusion of support of 64-bit addressing in the driver allows to increase the productivity considerably.
  • The support of 32-bit in-out. If a driver uses DMA procedures correctly with Windows 2000, it should also function normally with 64-bit systems.
  • A driver must support both 32-bit and 64-bit versions of IOCTL commands.

It is necessary to mention the fact that Microsoft provides the developers with instructions of code migration for new versions of Windows DDK as much as possible.

Possible Code Problems

The list of possible problems of code migration is given in [1, 2]. But these problems are only named there. And here we shall consider variants of their solutions in detail.

So, MSDN recommends us to use:

  • New data types, secure from the point of view of Win64. These are, first of all, types of fixed length as well as types meant especially for pointer storage.
  • Correct format lines in printf-like functions. As the size of pointers with 32-bit and 64-bit is different, so we can't use one and the same format line. The perfect solution here is total refusal to use such functions instead of using less dangerous analogues.
  • When it is necessary to cut off a pointer, one should use PtrToLong and PtrToUlong functions. Yet, you'd better alter the code in such a way that this operation becomes unnecessary. The matter is that the pointer becomes incorrect after such an operation.
  • One should use FIELD_OFFSET and TYPE_ALIGNMENT macros instead of explicit evaluation of the position of variable in the structure or manual alignment calculation. This is concerned with different types of alignment and the size of pointers.

Special attention should be paid to:

  • Operations with signed variables and unsigned variables. The questions of variable type conversion often cause misunderstanding; that's why it's better to avoid them.
  • Function call, where one of the parameters is a pointer. The potential error may be located both inside the function and outside of it when the result of its work is used.
  • The use of magic constants which may change depending upon the digit capacity of the system. Notice, that the number -1 with a 64-bit system is not equal to 0xffffffff as it used to be with a 32-bit one. What is this number equal to then? Naturally, it is equal to 0xffffffffffffffff, whereas 0xffffffff equals only to 0x00000000ffffffff.
  • Structures which contain pointers. The changes of address space occurred in 64-bit systems may directly affect the functioning of drivers.
  • The conversion of pointers to some data types (int, long).


To check the efficiency of drivers it is advisable to use appropriate tools. In addition to the maximum level of compiler diagnostics (/W4 or even /Wall) it is necessary to use other opportunities without fail.

First of all, take a note of a free tool created by Microsoft, PREfast analyzer if you are not aware of it yet. It's a static code analyzer; it discovers a great number of errors which can be found in common programs besides the errors we have considered above.

Another static code analyzer, Viva64, is meant for search of the errors in C++ programs which appear when the code migration from 32-bit systems to 64-bit ones is performed.


As you may see, the development of 64-bit drivers is quite easy and the tools which can facilitate this work are available. And this means that you don't have to put off the work.


  • Designing for 64-bit Windows.

Popular related articles
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →