I started with one problem but in the course of creating a test version I found two more.
The more the merrier! Anyway, the two problems revolve around getting errors that
depend upon what the scope of some UDT declares are, LOCAL or STATIC.
Problem 1) A UDT defined LOCAL doesn't work with the SIZEOF function, returning zero.
Problem 2) In another case, a UDT defined STATIC will cause a GPF in a function call.
Any advice most welcome!
---
The code below illustrates the Problems, which are marked by '*******' comments.
This should compile on most any Windows OS that has USB support (maybe not Win95 OSR2).
------------------
Mark Newman
[This message has been edited by Mark Newman (edited April 10, 2001).]
The more the merrier! Anyway, the two problems revolve around getting errors that
depend upon what the scope of some UDT declares are, LOCAL or STATIC.
Problem 1) A UDT defined LOCAL doesn't work with the SIZEOF function, returning zero.
Problem 2) In another case, a UDT defined STATIC will cause a GPF in a function call.
Any advice most welcome!
---
The code below illustrates the Problems, which are marked by '*******' comments.
This should compile on most any Windows OS that has USB support (maybe not Win95 OSR2).
Code:
' HID.BAS ' Program for testing the HID/USB drivers ' ' Requires that a current SETUPAPI.DLL and HID.DLL be present (should be on systems with ' USB support) ' ' This program just enumerates the HID (Human Interface Device) interfaces ' and shows their Symbolic Link name ' #Compile Exe "hid.exe" #Dim All #Register None #Include "win32api.inc" ' GUID Data Type Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Type SP_DEVICE_INTERFACE_DATA cbSize As Dword InterfaceClassGuid As GUID Flags As Dword Reserved As Dword End Type Type SP_DEVICE_INTERFACE_DETAIL_DATA cbSize As Dword DevicePath As Asciiz * 100 End Type %DIGCF_PRESENT = &H00000002 %DIGCF_DEVICEINTERFACE = &H00000010 ' Function declares Declare Sub HidD_GetHidGuid StdCall Lib "HID.DLL" Alias "HidD_GetHidGuid" _ ( _ HidGuid As GUID _ ) Declare Function SetupDiGetClassDevs Cdecl Lib "Setupapi.dll" Alias "SetupDiGetClassDevsA" _ ( _ ByRef ClassGuid As GUID, _ ByRef Enumerator As Dword, _ ByVal hwndParent As Long, _ ByVal Flags As Dword _ ) As Dword Declare Function SetupDiEnumDeviceInterfaces Cdecl Lib "Setupapi.dll" Alias "SetupDiEnumDeviceInterfaces" _ ( _ ByVal DeviceInfoSet As Dword, _ ByVal DeviceInfoData As Dword, _ ByRef InterfaceClassGuid As GUID, _ ByVal MemberIndex As Dword, _ ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA _ ) As Long Declare Function SetupDiGetDeviceInterfaceDetail Cdecl Lib "Setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" _ ( _ ByVal DeviceInfoSet As Dword, _ ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, _ ByRef DeviceInterfaceDetailData As SP_DEVICE_INTERFACE_DETAIL_DATA, _ ByVal DeviceInterfaceDetailDataSize As Dword, _ ByRef RequiredSize As Dword, _ ByVal DeviceInfoData As Dword _ ) As Long Declare Function SetupDiDestroyDeviceInfoList Cdecl Lib "Setupapi.dll" Alias "SetupDiDestroyDeviceInfoList" _ ( _ ByVal DeviceInfoSet As Dword _ ) As Long ' *********************************************************************** ' Compiler directives: Only use one option at a time %TEST_NORMAL = 1& '%TEST_SIZEOF = 1& '%TEST_GPF = 1& ' *********************************************************************** Function PbMain ' ' Program start ' Local hDevInfo As Dword Ptr Local dwReqLen As Dword Local dwInstance As Dword Local tHidGuid As GUID ' *********************************************************************** #If %Def(%TEST_NORMAL) Static tIfcData As SP_DEVICE_INTERFACE_DATA Local tIfcDetail As SP_DEVICE_INTERFACE_DETAIL_DATA #ElseIf %Def(%TEST_SIZEOF) Local tIfcData As SP_DEVICE_INTERFACE_DATA Static tIfcDetail As SP_DEVICE_INTERFACE_DETAIL_DATA #ElseIf %Def(%TEST_GPF) Static tIfcData As SP_DEVICE_INTERFACE_DATA Static tIfcDetail As SP_DEVICE_INTERFACE_DETAIL_DATA #EndIf ' *********************************************************************** ' Get the GUID of the HID interface HidD_GetHidGuid tHidGuid Do MsgBox "SetupDiGetClassDevs next" ' Get handle to relevant device information set hDevInfo = SetupDiGetClassDevs(tHidGuid, %NULL, %NULL, %DIGCF_PRESENT Or %DIGCF_DEVICEINTERFACE) If hDevInfo = %INVALID_HANDLE_VALUE Then MsgBox "No HDEVINFO available for this GUID" Exit Do End If ' Get interface data for the requested instance tIfcData.cbSize = SizeOf(tIfcData) ' *********************************************************************** ' Problem 1: ' When %TEST_SIZEOF is true, the SIZEOF function returns 0, not 28 ' *********************************************************************** MsgBox "Size of tIfcData (should be 28):" & Str$(tIfcData.cbSize) MsgBox "SetupDiEnumDeviceInterfaces next" ' *********************************************************************** ' Problem 2: ' When %TEST_GPF is true, this function call causes a GPF ' *********************************************************************** If IsFalse SetupDiEnumDeviceInterfaces(hDevInfo, %NULL, tHidGuid, dwInstance, tIfcData) Then MsgBox "SetupDiEnumDeviceInterfaces failed" SetupDiDestroyDeviceInfoList hDevInfo Exit Do End If ' Get the size of symbolic link name MsgBox "SetupDiGetDeviceInterfaceDetail - Get Buffer Size next" SetupDiGetDeviceInterfaceDetail hDevInfo, tIfcData, ByVal %NULL, 0???, dwReqLen, %NULL If dwReqLen = 0 Then MsgBox "SetupDiGetDeviceInterfaceDetail - Get Buffer Size failed" SetupDiDestroyDeviceInfoList hDevInfo Exit Do End If MsgBox "Size of buffer (should be 86) =" & Str$(dwReqLen) ' Set the size param to 5 - DWORD size plus 1 tIfcDetail.cbSize = 5 ' Get symbolic link name MsgBox "SetupDiGetDeviceInterfaceDetail - Get Symbolic Link Name next" If IsFalse SetupDiGetDeviceInterfaceDetail(hDevInfo, tIfcData, tIfcDetail, dwReqLen, ByVal %NULL, %NULL) Then MsgBox "SetupDiGetDeviceInterfaceDetail - Get Symbolic Link Name failed" SetupDiDestroyDeviceInfoList hDevInfo Exit Do End If MsgBox "Symbolic link is " & tIfcDetail.DevicePath Incr dwInstance Loop End Function
------------------
Mark Newman
[This message has been edited by Mark Newman (edited April 10, 2001).]
Comment