I have the following code used to create a valid handle using CreateFile
working on a 32 bit XP OS. When testing the same code on a 64 bit Vista and Windows 7 computer, CreateFile
returns an invalid handle value. I can not seem to figure out what is going on.
Here is the dll import:
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateFile(
string FileName,
uint DesiredAccess,
uint ShareMode,
IntPtr SecurityAttributes,
uint CreationDisposition,
uint FlagsAndAttributes,
IntPtr hTemplateFile
);
And the call:
drive = CreateFile(devicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_DELETE_ON_CLOSE,
IntPtr.Zero);
devicePath
is a valid path to the usb. This returns a valid handle on a 32 bit OS and an invalid value on a 64 bit OS. I have searched and searched and found nothing. If anyone could help or share some information I would be thankful.
Regards.