No, it is not 64 bit safe. Although your hDeviceInfo correctly defined as IntPtr , you treat it like a 32-bit value when you compare it.
In addition, you do not want to compare with IntPtr.Zero . SetupDiGetClassDevs returns INVALID_HANDLE_VALUE when it fails. INVALID_HANDLE_VALUE is -1. You must compare all 64 bits of the value to determine if the function worked. If you try something like:
if (hDeviceInfo.ToInt32() != -1)
Then you risk the error if the return value is something like 0x100000001.
It is best to use SafeHandle rather than IntPtr .
source share