The correct approach is to cast the pointer to ULONG_PTR, as shown in the following: PDEVICE_RELATIONS pDeviceRelations
This code sample erroneously casts the pDeviceRelations pointer to type ULONG, which can truncate the pointer value if sizeof(pDeviceRelations) > sizeof(ULONG). Irp->IoStatus.Information = (ULONG)pDeviceRelations // wrong The following code shows what not to do when copying a 64-bit pointer value to this field: PDEVICE_RELATIONS pDeviceRelations An unsigned integer of type DWORD_PTR or ULONG_PTR is always large enough to store the entire pointer, regardless of whether the code is compiled for a 32- or 64-bit machine.įor example, the IRP pointer field IoStatus. A better approach is to cast the pointer to type DWORD_PTR or ULONG_PTR. Casting a pointer to type DWORD or ULONG can cause a 64-bit pointer to be truncated. For 64-bit code, this assumption is dangerous. Programmers with experience writing code for 32-bit machines might be used to assuming that a pointer value fits into a DWORD or ULONG. Some of the pitfalls that you might encounter in writing a 64-bit audio driver are described below.įirst and foremost, a potential problem to look for in existing 32-bit driver code is conversion between pointer types and integer types such as DWORD or ULONG. If you are writing a 64-bit driver or writing a driver that can be compiled to run on both 32- and 64-bit systems, follow the porting guidelines in Driver Programming Techniques.