Help
I have code that Works fine in VB6, that I have attempted to convert to VB.net
I do a Call HidD_GetHidGuid(HidGuid), and it looks like it gets the right info, then I do a call to SetupDiGetClassDevs(HidGuid, 0, 0, &H12) and Get a Handle, different than in VB6 but I thought it was due to diff of varible sizes. But when I loop through trying to find my device using SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData), while I get no errors, but I never find any devices, even though I know I should get a couple of HID devices. I don't think I am passing the right stuff to the API's, but don't know where to turn. I've tried changing what and how I pass to the API's, but other than generating an errors that GetLastError() always returns as a 126 (The specified module could not be found) I can't get it to work. Can anybody Help? I'm way behind in this project. 4 10341
On 2004-04-15, Dale McGorman <k8**@arrl.net> wrote: Help,
I have code that Works fine in VB6, that I have attempted to convert to VB.net. I do a Call HidD_GetHidGuid(HidGuid), and it looks like it gets the right info, then I do a call to SetupDiGetClassDevs(HidGuid, 0, 0, &H12) and Get a Handle, different than in VB6 but I thought it was due to diff of varible sizes. But when I loop through trying to find my device using SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData), while I get no errors, but I never find any devices, even though I know I should get a couple of HID devices. I don't think I am passing the right stuff to the API's, but don't know where to turn. I've tried changing what and how I pass to the API's, but other than generating an errors that GetLastError() always returns as a 126 (The specified module could not be found) I can't get it to work. Can anybody Help? I'm way behind in this project.
It would be a lot easier to diagnose your problem if you posted your
code. Specifically your api declarations and a sample of how your using
the functions.
--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
In the long run, every program becomes rococco, and then rubble.
-- Alan Perlis
On 2004-04-15, Dale McGorman <k8**@arrl.net> wrote: Help,
I have code that Works fine in VB6, that I have attempted to convert to VB.net. I do a Call HidD_GetHidGuid(HidGuid), and it looks like it gets the right info, then I do a call to SetupDiGetClassDevs(HidGuid, 0, 0, &H12) and Get a Handle, different than in VB6 but I thought it was due to diff of varible sizes. But when I loop through trying to find my device using SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData), while I get no errors, but I never find any devices, even though I know I should get a couple of HID devices. I don't think I am passing the right stuff to the API's, but don't know where to turn. I've tried changing what and how I pass to the API's, but other than generating an errors that GetLastError() always returns as a 126 (The specified module could not be found) I can't get it to work. Can anybody Help? I'm way behind in this project.
It would be a lot easier to diagnose your problem if you posted your
code. Specifically your api declarations and a sample of how your using
the functions.
--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
In the long run, every program becomes rococco, and then rubble.
-- Alan Perlis
OK
Here it is
Declaration
I've only worked on the first three API Calls so far, so there may be probems in some of the other
Public Structure Device_Interface_Dat
Dim cbsize As Int3
Dim InterfaceClassGuid As Gui
Dim Flags As Int3
Dim ReservedPtr As Lon
End Structur
Public Structure Device_Interface_Detai
Public cbsize As Intege
'<VBFixedArray(256)
Public DataPath() As Byt
'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1026"
Public Sub Initialize(
ReDim DataPath(256
End Su
End Structur
Public Structure Security_Attribute
Public nLength As Intege
Public lpSecurityDescriptor As Intege
Public bInheritHandle As Intege
End Structur
Public Structure HidD_Attribute
Public Size As Lon
Public VendorID As Shor
Public ProductID As Shor
Public VersionNumber As Shor
End Structur
Public Structure SP_DEVINFO_DAT
Public cbsize As Intege
Public ClassGuid As Gui
Public DevInst As Intege
Public Reserved As Lon
End Structur
Public Class Win3
Declare Sub HidD_GetHidGuid Lib "HID.dll" (ByRef GuidPtr As Guid
Declare Auto Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA"
(ByRef GuidPtr, ByRef EnumPtr, ByRef HwndParent, ByVal Flags) As Lon
Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal Handle As Long, ByVal InfoPtr As Long, ByRef GuidPtr As Guid, ByVal MemberIndex As Integer, ByRef InterfaceDataPtr As SP_DEVINFO_DATA) As Intege
Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA"
(ByVal Handle, ByRef InterfaceDataPtr, ByRef InterfaceDetailPtr, ByVal DetailLength,
ByRef ReturnedLengthPtr, ByRef DevInfoDataPtr) As Boolea
'UPGRADE_WARNING: Structure Security_Attributes may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer,
ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As Security_Attributes,
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer,
ByVal hTemplateFile As Integer) As Intege
Declare Function HidD_GetAttributes Lib "HID.dll" (ByVal Handle As Integer, ByRef BufferPtr As Integer) As Intege
Declare Sub CloseHandle Lib "kernel32" (ByVal HandleToClose As Integer
Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Integer) As Boolea
Declare Function GetLastError Lib "kernel32" () As Intege
Declare Function FormatMessage Lib "kernel32" (ByVal dwFlags As Int32, ByVal lpSource As Int32, ByVal dwMessageId As Int32,
ByVal lpBuffer As Int32, ByVal nSize As Int32, ByVal arguments As Long) As Intege
End Clas
Function I am using. Have not gotten all the way through it so there are probably several things that need fixed. I never got anything to come back from the Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData) cal
Function OpenUSB() As Boolea
Dim PnPHandle As Int6
Dim HIDdevice As Lon
Dim BytesReturned As Lon
Dim inx As Int1
Dim HidName As Strin
Dim ThisHIDdevice As HidD_Attribute
Dim TempInt As Intege
Dim result As Boolea
Dim strTemp As Strin
Dim DeviceInterfaceData As Device_Interface_Dat
Dim FunctionClassDeviceData As Device_Interface_Detai
Dim SpDeviceInfoData As SP_DEVINFO_DATA
On Error GoTo OpenUSBErrHndlr
OpenUSB = True
' First, get my class identifier
Call Win32.HidD_GetHidGuid(HidGuid)
'strTemp = HidGuid.ToString
'
' Get a handle for the Plug and Play node and request currently active HID devices
PnPHandle = Win32.SetupDiGetClassDevs(HidGuid, 0, 0, &H12)
'If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")
FunctionClassDeviceData.Initialize()
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes
'
' Lets look for a maximum of 20 HID devices
For HIDdevice = 0 To 19
' Is there a HID device at this table entry
If Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData) Then
' There is a device here, get it's name
FunctionClassDeviceData.cbsize = 5
result = Win32.SetupDiGetDeviceInterfaceDetail(PnPHandle, DeviceInterfaceData, FunctionClassDeviceData.cbsize, _
Len(FunctionClassDeviceData), BytesReturned, 0)
' If (Success = 0) Then ErrorExit ("Could not find the system name for this HID device")
' Convert C string to Visual Basic String
HidName = "" : inx = 0
Do While FunctionClassDeviceData.DataPath(inx) <> 0
HidName = HidName & Chr(FunctionClassDeviceData.DataPath(inx))
inx = inx + 1
Loop
' Can now open this HID device
Dim SA As Security_Attributes
HidHandle = Win32.CreateFile(HidName, &HC0000000, 3, SA, 3, 0, 0)
If (HidHandle = -1) Then
' Note that Win2K opens system input devices (mouse, keyboard) for EXCLUSIVE use
strTemp = "System input HID detected"
Else
' Get VID and PID for display
result = Win32.HidD_GetAttributes(HidHandle, ThisHIDdevice.Size)
If (ThisHIDdevice.VendorID = 66) Then
OurDevHndl = HidHandle
Else
Call Win32.CloseHandle(HidHandle)
End If
End If
End If 'SetupDiEnumDeviceInterfaces
Next HIDdevice
Call Win32.SetupDiDestroyDeviceInfoList(PnPHandle)
Exit Function
OpenUSBErrHndlr:
Dim errNum As Int32
errNum = Win32.GetLastError()
OpenUSB = False
End Function
OK
Here it is
Declaration
I've only worked on the first three API Calls so far, so there may be probems in some of the other
Public Structure Device_Interface_Dat
Dim cbsize As Int3
Dim InterfaceClassGuid As Gui
Dim Flags As Int3
Dim ReservedPtr As Lon
End Structur
Public Structure Device_Interface_Detai
Public cbsize As Intege
'<VBFixedArray(256)
Public DataPath() As Byt
'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1026"
Public Sub Initialize(
ReDim DataPath(256
End Su
End Structur
Public Structure Security_Attribute
Public nLength As Intege
Public lpSecurityDescriptor As Intege
Public bInheritHandle As Intege
End Structur
Public Structure HidD_Attribute
Public Size As Lon
Public VendorID As Shor
Public ProductID As Shor
Public VersionNumber As Shor
End Structur
Public Structure SP_DEVINFO_DAT
Public cbsize As Intege
Public ClassGuid As Gui
Public DevInst As Intege
Public Reserved As Lon
End Structur
Public Class Win3
Declare Sub HidD_GetHidGuid Lib "HID.dll" (ByRef GuidPtr As Guid
Declare Auto Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA"
(ByRef GuidPtr, ByRef EnumPtr, ByRef HwndParent, ByVal Flags) As Lon
Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal Handle As Long, ByVal InfoPtr As Long, ByRef GuidPtr As Guid, ByVal MemberIndex As Integer, ByRef InterfaceDataPtr As SP_DEVINFO_DATA) As Intege
Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA"
(ByVal Handle, ByRef InterfaceDataPtr, ByRef InterfaceDetailPtr, ByVal DetailLength,
ByRef ReturnedLengthPtr, ByRef DevInfoDataPtr) As Boolea
'UPGRADE_WARNING: Structure Security_Attributes may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1050"
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer,
ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As Security_Attributes,
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer,
ByVal hTemplateFile As Integer) As Intege
Declare Function HidD_GetAttributes Lib "HID.dll" (ByVal Handle As Integer, ByRef BufferPtr As Integer) As Intege
Declare Sub CloseHandle Lib "kernel32" (ByVal HandleToClose As Integer
Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Integer) As Boolea
Declare Function GetLastError Lib "kernel32" () As Intege
Declare Function FormatMessage Lib "kernel32" (ByVal dwFlags As Int32, ByVal lpSource As Int32, ByVal dwMessageId As Int32,
ByVal lpBuffer As Int32, ByVal nSize As Int32, ByVal arguments As Long) As Intege
End Clas
Function I am using. Have not gotten all the way through it so there are probably several things that need fixed. I never got anything to come back from the Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData) cal
Function OpenUSB() As Boolea
Dim PnPHandle As Int6
Dim HIDdevice As Lon
Dim BytesReturned As Lon
Dim inx As Int1
Dim HidName As Strin
Dim ThisHIDdevice As HidD_Attribute
Dim TempInt As Intege
Dim result As Boolea
Dim strTemp As Strin
Dim DeviceInterfaceData As Device_Interface_Dat
Dim FunctionClassDeviceData As Device_Interface_Detai
Dim SpDeviceInfoData As SP_DEVINFO_DATA
On Error GoTo OpenUSBErrHndlr
OpenUSB = True
' First, get my class identifier
Call Win32.HidD_GetHidGuid(HidGuid)
'strTemp = HidGuid.ToString
'
' Get a handle for the Plug and Play node and request currently active HID devices
PnPHandle = Win32.SetupDiGetClassDevs(HidGuid, 0, 0, &H12)
'If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")
FunctionClassDeviceData.Initialize()
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes
'
' Lets look for a maximum of 20 HID devices
For HIDdevice = 0 To 19
' Is there a HID device at this table entry
If Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, SpDeviceInfoData) Then
' There is a device here, get it's name
FunctionClassDeviceData.cbsize = 5
result = Win32.SetupDiGetDeviceInterfaceDetail(PnPHandle, DeviceInterfaceData, FunctionClassDeviceData.cbsize, _
Len(FunctionClassDeviceData), BytesReturned, 0)
' If (Success = 0) Then ErrorExit ("Could not find the system name for this HID device")
' Convert C string to Visual Basic String
HidName = "" : inx = 0
Do While FunctionClassDeviceData.DataPath(inx) <> 0
HidName = HidName & Chr(FunctionClassDeviceData.DataPath(inx))
inx = inx + 1
Loop
' Can now open this HID device
Dim SA As Security_Attributes
HidHandle = Win32.CreateFile(HidName, &HC0000000, 3, SA, 3, 0, 0)
If (HidHandle = -1) Then
' Note that Win2K opens system input devices (mouse, keyboard) for EXCLUSIVE use
strTemp = "System input HID detected"
Else
' Get VID and PID for display
result = Win32.HidD_GetAttributes(HidHandle, ThisHIDdevice.Size)
If (ThisHIDdevice.VendorID = 66) Then
OurDevHndl = HidHandle
Else
Call Win32.CloseHandle(HidHandle)
End If
End If
End If 'SetupDiEnumDeviceInterfaces
Next HIDdevice
Call Win32.SetupDiDestroyDeviceInfoList(PnPHandle)
Exit Function
OpenUSBErrHndlr:
Dim errNum As Int32
errNum = Win32.GetLastError()
OpenUSB = False
End Function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: The Road To Utopia |
last post by:
Here's one for the trolls...a common jibe from them is setting up
audio/video hardware under linux.
Ok, true story: at work today, someone asked me if I could tell him why
his XP Home would play...
|
by: rhat |
last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant.
Can anyone shed some light on what this will change and it will break stuff
as converting HTML to XHTML pages DO break things. see,...
|
by: lkrubner |
last post by:
Is there any reason why this code wouldn't prompt someone to save their
work every 5 minutes? It doesn't seem to be working. This code shows up
in the HEAD of an HTML document.
function...
|
by: Lyle Fairfield |
last post by:
I created a new MS-SQL Database, "TestODBC".
I made Table1 and StoredProcedure1.
I made an ODBC DSN for that MS-SQL Database.
I created a new AccessXP mdb, "TestODBC".
I linked to the...
|
by: MGFoster |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've converted an ACC97 .mdb file to an ACC2K2 .adp. A report that
worked in ACC97 doesn't work in ACC2K2.
Report setup:
ACC97 ...
|
by: kernelxu |
last post by:
hi, everyone.
now, I'am confused on such a problem:
function setbuf(stdin, NULL) or setvbuf(stdin, NULL, _IONBF, 0)
can set the stadard input stream unbuffered.
however, why does my program...
|
by: Larry |
last post by:
These is a interface " IPerson" and a class "SoftwareDeveloper" support
the interface;
public __gc __interface IPerson
{
void Eat();
void Sleep(;
void Work();
|
by: tshad |
last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't
seem to get the Sub (writefile) to execute. It displays all the
response.write lines that are called directly, but not...
|
by: Adam J. Schaff |
last post by:
I have noticed that if a user closes a form via pressing return (either
while the OK button has focus or if AcceptButton is set to OK for the form)
then the "ENTER" keypress event fires ON THE...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |