473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need Help calling an API correctly

The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params to the API call SetupDiGetDeviceInterfaceDetail() I can get it to actully not fail, and it actully tells me that it returned 87 bytes which is correct, but it never fills my structure of DeviceInterfaceDetail, and of course return value is a failure because of it. I am sure that it is in how I am trying to pass the structure, but have tried several ways, but obviously don't know how to do it correctly. I have tried to use marshalby, but have never used it before, and probably not doing it correct. Can anyone help? I have only worked on getting code working up to this routine, so I know that the definitions for some of the other calls need to be fixed, but if you look at the code that Iincluded, those calls I think are correct, so if those definitions need fixed, let me know

**************** My Definition

Public cnCurrentDb As OleDbConnectio
Public dsCurrentDB As DataSe
Public ArryData(10, 4) As Objec
Public adProgData As OleDbDataAdapte
Public adProgName As OleDbDataAdapte
Public adRunActuals As OleDbDataAdapte
Public adRunInfo As OleDbDataAdapte
Public adProgSteps As OleDbDataAdapte
Public strSql As Strin
Public strDbName As Strin
Public FormReturn As Int1
Public HidHandle As Lon
Public OurDevHndl As Lon

Public Const HEADER_NAME = "WinCryo by Gordinier Electronics
Public Const MAX_TEMP = 4
Public Const MIN_TEMP = -20
Public Const MAX_RATE = 3
Public HidGuid As Gui
Public Structure Device_Interface_Dat
Dim cbsize As Int3
Dim InterfaceClassGuid As Gui
Dim Flags As Int3
Dim ReservedPtr As Intege
End Structur

<StructLayout(LayoutKind.Sequential)> Public Structure Device_Interface_Detai
Public cbsize As Intege
<MarshalAs(UnmanagedType.ByValArray, sizeconst:=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(255
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 Intege
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 As Guid,
ByRef EnumPtr As Integer,
ByRef HwndParent As Integer,
ByVal Flags As Integer)
As Intege

Declare Auto Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll"
(ByVal Handle As Integer,
ByVal InfoPtr As Integer,
ByRef GuidPtr As Guid,
ByVal MemberIndex As Integer,
ByRef InterfaceDataPtr As Device_Interface_Data)
As Boolea

Declare Auto Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA"
(ByVal Handle As Integer,
ByRef InterfaceData As Device_Interface_Data,
ByVal InterfaceDetail As Device_Interface_Detail,
ByVal DetailLength As Integer,
ByRef ReturnedLength As Integer,
ByVal DevInfoData As Integer)
As Boolea

Declare Auto Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByRef lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Security_Attributes, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) _
As Integer

'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 HidD_GetAttributes Lib "HID.dll" (ByVal Handle As Integer, ByRef BufferPtr As Integer) As Integer

Declare Sub CloseHandle Lib "kernel32" (ByVal HandleToClose As Integer)

Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Integer) As Boolean

Declare Function GetLastError Lib "kernel32" () As Integer

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 Integer

End Class
Dim DeviceInterfaceData As Device_Interface_Data
************** MY CODE
Function OpenUSB() As Boolean

Dim PnPHandle As Int64
Dim HIDdevice As Long
Dim BytesReturned As Long
Dim inx As Int16
Dim HidName As String
Dim ThisHIDdevice As HidD_Attributes
Dim TempInt As Integer
Dim result As Boolean
Dim strTemp As String
Dim errNum As Int32
Dim ArrySize As Integer

Dim DeviceInterfaceData As Device_Interface_Data
Dim DeviceInterfaceDetail As Device_Interface_Detail
Dim DeviceInfoData 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")

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
DeviceInterfaceDetail.Initialize()
DeviceInterfaceDetail.cbsize = 5

If Win32.SetupDiEnumDeviceInterfaces(PnPHandle, 0, HidGuid, HIDdevice, DeviceInterfaceData) Then
' There is a device here, get it's name

result = Win32.SetupDiGetDeviceInterfaceDetail(PnPHandle, DeviceInterfaceData, DeviceInterfaceDetail, _
DeviceInterfaceDetail.cbsize, BytesReturned, 0)

********* This last call is where I am having trouble ******************
Nov 22 '05 #1
0 1941

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
2
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the...
0
by: Dale McGorman | last post by:
The following is some code that I am trying to bring over from VB 6.0, that I have working there. I am trying to get to where I can talk to a USB device. I am stuck on how to correctly pass params...
3
by: Angel | last post by:
Hello again (and again, and again...) I think I'm getting closer to solving my initial problem of calling unmanaged code. I managed to call the functions with user-defined structs w/o getting any...
6
by: Phillip N Rounds | last post by:
I have an application which is heavily graphics intensive, all the graphics being custom. Scattered throughout by app, I have MyView->OnDraw( this->GetDC() ); Apparently, each call to ...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
2
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe...
2
by: Buddy Robbins | last post by:
Hey folks, I am in desparate need of help to solve my problem. I have written a service that examines a table in a database, and creates a directory hierarchy based on data in the table. It...
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.