none
请教在VB.NET中DeviceIoControl API函数的用法(谢谢了) RRS feed

  • 问题

  • 最近在用VB.NET编写一个USB的驱动程序,里边涉及到createfile,deviceiocontrol等几个API函数的调用。我能找到的资料都是VB6.0的,在调用deviceiocontrol函数的时候老是报错。我调用的相关CODE如下,盼能指点在VB.NET中要如何定义及调用deviceiocontrol函数。

    1.定义部分:

    ' = = = = 列出所需的W I N A P I函式 = = = =

        Public Declare Auto Function CreateFile Lib "kernel32.dll" _

       (ByVal lpFileName As String, ByVal dwDesiredAccess As Int32, _

          ByVal dwShareMode As Int32, ByVal lpSecurityAttributes As IntPtr, _

             ByVal dwCreationDisposition As Int32, ByVal dwFlagsAndAttributes As Int32, _

                ByVal hTemplateFile As IntPtr) As IntPtr

    Public Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As Object, ByVal nInBufferSize As Integer, ByVal lpOutBuffer As Object,

               2.应用部分

               Dim result As Long

            Dim driverName As String

            driverName = "\\.\" & sDriverName      '設定FX2-56核心單板裝置的符號鏈結字串名稱

            result = CreateFile(driverName, GENERIC_READ Or GENERIC_WRITE, (FILE_SHARE_READ Or FILE_SHARE_WRITE), 0, OPEN_EXISTING, 0, 0)

         result = DeviceIoControl(hDriverHandle, IOCTL_Ezusb_GET_PIPE_INFO, pi, Len(pi), pi, Len(pi), lBytesReturned, 0)

        

         程序在一执行deviceiocontrol函数调用时就报错,不知什么原因。

         盼有人能告知在VB.NET中应用DeviceIoControl函数的定义方式及用法!!!,谢谢

    2010年4月8日 3:27