Attribute VB_Name = "Модуль3"

#If Win64 Then
    Public Declare PtrSafe Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" _
            (ByVal hKey As Long, ByVal dwIndex As Long, _
            ByVal lpName As String, _
            ByVal cbName As Long) As Long
    Public Declare PtrSafe Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
            (ByVal hKey As Long, ByVal lpSubKey As String, _
            ByVal ulOptions As Long, ByVal samDesired As Long, _
            phkResult As Long) As Long
    Public Declare PtrSafe Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
#Else
    Public Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" _
            (ByVal hKey As Long, ByVal dwIndex As Long, _
            ByVal lpName As String, _
            ByVal cbName As Long) As Long
    Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
            (ByVal hKey As Long, ByVal lpSubKey As String, _
            ByVal ulOptions As Long, ByVal samDesired As Long, _
            phkResult As Long) As Long
    Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
#End If

Public Const KEY_QUERY_VALUE = &H8
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const ERROR_SUCCESS = 0&
Global Const ERROR_NO_MORE_ITEMS = 259

Function GetODBCDriver() As String
    Dim lcDriver As String, lcKey As String
    Dim hKey As Long, lnSize As Long, e As Long, i As Long
    Dim llFox As Boolean, llVisual As Boolean
    e = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBCINST.INI", 0, KEY_QUERY_VALUE, hKey)
    i = 0
    llFox = False
    llVisual = False
    Do
        lcKey = Space(250)
        lnSize = Len(lcKey)
        e = RegEnumKey(hKey, i, lcKey, lnSize)
        If Trim(lcKey) <> "" Then
            lcDriver = Mid(Trim(lcKey), 1, Len(Trim(lcKey)) - 1)
            llFox = llFox Or lcDriver Like "Microsoft FoxPro Driver*"
            llVisual = llVisual Or lcDriver Like "Microsoft Visual FoxPro Driver*"
        End If
        i = i + 1
    Loop While e = ERROR_SUCCESS
    RegCloseKey hKey
    GetODBCDriver = IIf(llVisual, "Microsoft Visual FoxPro Driver", IIf(llFox, "Microsoft FoxPro Driver (*.dbf)", "Microsoft Visual FoxPro Driver"))
End Function
