I am trying to use CreateFile to get a handle for a USB device. It is in some code that I am converting from .NET to .NETCF. For some reason the following call to CreateFile returns a value of -1 every time. I know the device is working fine because I can get a handle to it in regular .NET.
I use the following import: I suspect "Kernel32.dll" should be replaced with CoreDLL when it is actually deployed on the CF, but I don't see why Kernel32 shouldn't work to test on a .NET system.Code:Dim extra As New IntPtr extra = CreateFile(diDetail.DevicePath, FileAccess.ReadWrite, FileShare.ReadWrite, Nothing, FileMode.Open, EFileAttributes.Overlapped, IntPtr.Zero)
If my post doesn't make it obvious, I am far from an expert on the Compact Framework, and may have inherited a project a bit over my head. Hoping someone can help or at least point me in the right direction.Code:'Kernel32.dll is used on XP and in standard .NET. In Windows CE and NET Compact it may need to be changed to coredll.dll <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Shared Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As UInt32, ByVal dwShareMode As UInt32, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As UInt32, ByVal dwFlagsAndAttributes As UInt32, ByVal hTemplateFile As IntPtr) As IntPtr End Function


Reply With Quote
