CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2011
    Posts
    6

    CreateFile DLL Troubles

    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.

    Code:
    Dim extra As New IntPtr
                        extra = CreateFile(diDetail.DevicePath, FileAccess.ReadWrite, FileShare.ReadWrite, Nothing, FileMode.Open, EFileAttributes.Overlapped, IntPtr.Zero)
    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:
    '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
    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.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CreateFile DLL Troubles

    Call Marshal.GetLastWin32Error to find out why.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured