就像用API Viewer加载Win32API一样,我如何才能方便的查看ODBC API并加以调用?

解决方案 »

  1.   

    Private Const SQL_SUCCESS As Long = 0
    Private Const SQL_ERROR As Long = -1
    Private Const SQL_FETCH_NEXT As Long = 1Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv As Long, ByVal fDirection As Integer, ByVal szDSN As String, ByVal cbDSNMax As Integer, pcbDSN As Integer, ByVal szDescription As String, ByVal cbDescriptionMax As Integer, pcbDescription As Integer) As Integer
    Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (env As Long) As Integer'搜索系统中所有的DSN(ODBC)数据源和对应的驱动 0表示失败,其余数值表示返回的驱动或数据源的数量(数组从1开始)
    Public Function fun_GetDSNsAndDrivers(ByRef strArr_DSNs() As String, ByRef strArr_DRVs() As String) As Long
    Dim int_Ret As Integer
    Dim sDSNItem As String * 1024
    Dim sDRVItem As String * 1024
    Dim int_I As Integer
    Dim sDSN As String
    Dim sDRV As String
    Dim iDSNLen As Integer
    Dim iDRVLen As Integer
    Dim lHenv As Long '对环境处理On Error GoTo doErrorReDim strArr_DSNs(0) As String
    ReDim strArr_DRVs(0) As String
    If SQLAllocEnv(lHenv) <> SQL_ERROR Then
    int_I = 0
    sDSNItem = Space(1024)
    sDRVItem = Space(1024)
    int_Ret = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
    Do Until int_Ret <> SQL_SUCCESS
    sDSN = Left$(sDSNItem, iDSNLen)
    sDRV = Left$(sDRVItem, iDRVLen)
    int_I = int_I + 1
    If int_I = 1 Then
    ReDim strArr_DSNs(1 To 1) As String
    ReDim strArr_DRVs(1 To 1) As String
    Else
    ReDim Preserve strArr_DSNs(1 To int_I) As String
    ReDim Preserve strArr_DRVs(1 To int_I) As String
    End If
    strArr_DSNs(int_I) = sDSN
    strArr_DRVs(int_I) = sDRV
    sDSNItem = Space(1024)
    sDRVItem = Space(1024)
    int_Ret = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
    Loop
    fun_GetDSNsAndDrivers = int_I
    Else
    fun_GetDSNsAndDrivers = 0
    End If
    Exit Function
    doError:
    fun_GetDSNsAndDrivers = 0
    End Function