Bericht 1 van 4NL Computer Forum ~ SQL & Programmeren Van | : | Peter | Datum | : | 05-07-2006 |
Aan | : | Allen | MsgID | : | 3007.1 |
Onderwerp | : | SetupDI... API | Forum | : | ws-nlcomputer |
Hoi,
Hoe kan ik de eigenschap 'PortName' uit de registry lezen met een SetupDI... API call.
Dit ivm het gebruik van een USB <> Serieel Adapter.
Het probleem in onderstaande routine is dat SetupDiOpenDevKey steeds -1teruggeeft en Err.LastDllError is dan 6
iemand enig idee of een andere oplossing?
'class of 'Ports'
mGUID = sGuid2Guid("4D36E978-E325-11CE-BFC1-08002BE10318")
'get class as long
hDevInfoC = SetupDiGetClassDevs(mGUID, vbNullString, 0, DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
DIDC.cbSize = Len(DIDC)
Do
ret = SetupDiEnumDeviceInfo(hDevInfoC, i, DIDC)
If ret > 0 Then
'found an item...
ret = SetupDiOpenDevRegKey(hDevInfoC, DIDC, &H0, &H0, DIREG_DEV, KEY_QUERY_VALUE)
If ret > 0 Then
'valid registry key...
lKey = 0 'Long value required here
lKeyType = REG_SZ
ret = RegQueryValueEx(lKey, "PortName", 0, lKeyType, buf, 255)
If ret > 0 Then
'found the property
If lKeyType = REG_SZ then
MsgBox "Found it !"
End If
Else
MsgBox "RegQueryValueEx() failed."
End If
ret = RegCloseKey(lKey)
Else
MsgBox "SetupOpenDevRegKey() failed."
End If
Else
'no more items
Exit Do
End If
i = i + 1
Loop
Peter
Bericht 2 van 4NL Computer Forum ~ SQL & Programmeren Van | : | Just Vecht (Sysop) | Datum | : | 16-07-2006 |
Aan | : | Peter | MsgID | : | 3007.2 |
Onderwerp | : | SetupDI... API | Forum | : | ws-nlcomputer |
Beste Peter,
Ik zie dat je jammer genoeg geen antwoord op je bericht gekregen hebt. Kom toch nog eens terug naar het forum. Niet iedereen komt elke dag op bezoek en wellicht komt men toch met de juiste reactie.
We houden in de gaten of er een reactie volgt en anders brengen we je bericht weer onder de aandacht.
groetjes,
Just Vecht
mijn Blog en meer
Bericht 3 van 4NL Computer Forum ~ SQL & Programmeren Van | : | Ronald Beuker | Datum | : | 14-08-2006 |
Aan | : | Peter | MsgID | : | 3007.3 |
Onderwerp | : | SetupDI... API | Forum | : | ws-nlcomputer |
Hoi Peter,
Ik pretendeer niet het onderstaande allemaal volledig te begrijpen, maar met deze code lukte het mij om een specifieke registry-key uit te lezen. Misschien heb je er wat aan! ;-)
De
\HKEY_LOCAL_MACHINE\Software\Professional Planner sleutel heeft een tekenreekswaarde "ApplicationPath". Hieronder lees ik de waarde daarvan uit. Ik weet dat er nog wat code gestript kan worden, maar ik heb het maar zo gelaten (opdat ik niet te veel wis en het niet meer werkt <g>).
Groeten,
Ronald (Sysop)
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" _
Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" _
Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal _
lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey _
As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, lpData _
As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Const REG_SZ = 1 'Unicode nul terminated string
Const REG_BINARY = 3 'Free form binary
Const REG_DWORD = 4 '32-bit number
Const ERROR_SUCCESS = 0&
Dim ApplicationPath As String
Private Sub Form_Load()
ApplicationPath = GetSettingString(HKEY_LOCAL_MACHINE, "SOFTWARE\Professional Planner", "ApplicationPath")
End Sub
Public Function GetSettingString(hKey As Long, _
strPath As String, strValue As String, Optional _
Default As String) As String
Dim hCurKey As Long
Dim lResult As Long
Dim lValueType As Long
Dim strBuffer As String
Dim lDataBufferSize As Long
Dim intZeroPos As Integer
Dim lRegResult As Long
'Set up default value
If Not IsEmpty(Default) Then
GetSettingString = Default
Else
GetSettingString = ""
End If
lRegResult = RegOpenKey(hKey, strPath, hCurKey)
lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _
lValueType, ByVal 0&, lDataBufferSize)
If lRegResult = ERROR_SUCCESS Then
If lValueType = REG_SZ Then
strBuffer = String(lDataBufferSize, " ")
lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, _
ByVal strBuffer, lDataBufferSize)
intZeroPos = InStr(strBuffer, Chr$(0))
If intZeroPos > 0 Then
GetSettingString = Left$(strBuffer, intZeroPos - 1)
Else
GetSettingString = strBuffer
End If
End If
Else
'there is a problem
End If
lRegResult = RegCloseKey(hCurKey)
End Function
Bericht 4 van 4NL Computer Forum ~ SQL & Programmeren Van | : | Peter | Datum | : | 14-08-2006 |
Aan | : | Ronald Beuker | MsgID | : | 3007.4 |
Onderwerp | : | SetupDI... API | Forum | : | ws-nlcomputer |
Hoi Ronald,
Bedankt voor je antwoord. Helaas schiet ik er nix mee op.
Ik heb maar een middenweg gekozen tussen SetupDI... en recht-toe-recht-aan de Registry uitlezen.
Xp en Vista lusten het allebei :-)
groeten, Peter