Achei um com declarações mais completas.
Código: Selecionar todos
Const SQL_NULL_HANDLE = 0
Const SQL_HANDLE_ENV = 1
Const SQL_FETCH_NEXT = 1
Const SQL_FETCH_FIRST = 2
Const SQL_SUCCESS = 0
Const SQL_ATTR_ODBC_VERSION = 200
Const SQL_OV_ODBC2 = 2
Const SQL_IS_INTEGER = -6
Dim nRetCode As Long
Private Declare Function SQLDrivers Lib "odbc32.dll" (ByVal _
EnvironmentHandle As Long, ByVal Direction As Integer, _
ByVal DriverDescription As String, ByVal BufferLength1 As Integer, _
DescriptionLengthPtr As Integer, ByVal DriverAttributes As String, _
ByVal BufferLength2 As Integer, AttributesLengthPtr As Integer) As Integer
' Note that pointers to numbers are passed as numbers by reference!
Private Declare Function SQLDataSources Lib "odbc32.dll" (ByVal _
EnvironmentHandle As Long, ByVal Direction As Integer, _
ByVal ServerName As String, ByVal BufferLength1 As Integer, _
NameLength1Ptr As Integer, ByVal Description As String, _
ByVal BufferLength2 As Integer, NameLength2Ptr As Integer) As Integer
Private Declare Function SQLFreeHandle Lib "odbc32.dll" (ByVal _
HandleType As Integer, ByVal Handle As Long) As Integer
Private Declare Function SQLAllocHandle Lib "odbc32.dll" (ByVal _
HandleType As Integer, ByVal InputHandle As Long, _
OutputHandlePtr As Long) As Integer
Private Declare Function SQLSetEnvAttr Lib "odbc32.dll" (ByVal _
EnvironmentHandle As Long, ByVal EnvAttribute As Long, _
ByVal ValuePtr As Long, ByVal StringLength As Long) As Integer
Private Declare Function SQLDisconnect Lib "odbc32.dll" (ByVal _
ConnectionHandle As Long) As Integer
'//This function will print list of installed driver name and attributes
Private Sub ListODBCDrivers()
' Prints a list of ODBC drivers on system
Dim lHEnv As Long
Dim sDriverDesc As String * 1024
Dim sDriverAttr As String * 1024
Dim sDriverAttributes As String
Dim nDriverDescLength As Integer
Dim nAttrLength As Integer
Dim x As Integer
Dim sAll As String
' Allocate an environment handle.
nRetCode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, lHEnv)
' Set ODBC behavior
nRetCode = SQLSetEnvAttr(lHEnv, SQL_ATTR_ODBC_VERSION, _
SQL_OV_ODBC2, SQL_IS_INTEGER)
' Get first driver
nRetCode = SQLDrivers(lHEnv, _
SQL_FETCH_FIRST, _
sDriverDesc, _
Len(sDriverDesc), _
nDriverDescLength, _
sDriverAttr, _
Len(sDriverAttr), _
nAttrLength)
sAll = ""
Me.WindowState = vbMaximized
Me.AutoRedraw = True
Do While nRetCode = SQL_SUCCESS
'//Replace NULL separators with colons in attribute string
sDriverAttributes = Left$(sDriverAttr, nAttrLength - 1)
sDriverAttributes = Replace(sDriverAttributes, Chr(0), " : ")
'//Remove NULL in ODBC Driver name
sDriverDesc = Left$(sDriverDesc, nDriverDescLength)
sDriverDesc = Replace(sDriverDesc, Chr(0), "")
sAll = sAll & sDriverDesc & " ==> " & sDriverAttributes & vbCrLf
Me.Print sDriverDesc '//Print driver name
Me.Print sDriverAttributes '//Print driver attribute
Me.Print String(100, "-")
Debug.Print sDriverDesc '//Print driver name
Debug.Print sDriverAttributes '//Print driver attribute
Debug.Print String(100, "-")
'//Next data source
nRetCode = SQLDrivers(lHEnv, _
SQL_FETCH_NEXT, _
sDriverDesc, _
Len(sDriverDesc), _
nDriverDescLength, _
sDriverAttr, _
Len(sDriverAttr), _
nAttrLength)
Loop
'Debug.Print "ODBC Drivers"
'Debug.Print sAll
nRetCode = SQLFreeHandle(SQL_HANDLE_ENV, lHEnv)
End Sub
Private Sub Form_Load()
ListODBCDrivers
End Sub
https://binaryworld.net/Main/CodeDetail ... =3875#copy
Basicamente é a mesma coisa, mas aqui mostra os tipos necessários, e daria pra fazer sem linguagem C, e sem a LIB, diretamente com a DLL do Windows.
Uma coisa a prestar atenção é na declaração, não apenas no tipo.
No harbour usamos funcao( x, @y ) pra passar por referência, isso é feito na chamada da função.
No VB isso não é na chamada, é na função. É a função que vai dizer se é por referência. function funcao( byval x, y ), o x é normal e o y é por referência
Além disso, como são linguagens de programação diferentes, a variável por referência precisa ter conteúdo adequado.
Se vai retornar uma string de até 1024 caracteres, precisa passar a variável string com no mínimo 1024 caracteres, ou dá GPF.
Isso é porque por referência é o "pointer", a posição da memória aonde a variável está, se definir tamanho pequeno, o resultado vai invadir memória que não pertence à variável/programa, por isso windows acusa GPF ou violação de memória.
É por isso que geralmente criam funções intermediárias no harbour, pra tratar esse tipo de coisa e o programador não se preocupar com isso.
E com base nisso dá pra aproveitar muito fonte pronto do VB6, não apenas esse.
Quem usa a LIB do ACBR faz muito uso disso, talvez sem ter percebido, porque pega o fonte pronto que eles fornecem.
Tava aqui pensando... se alimentar a IA com isso, ela pode fornecer muita coisa pronta pro harbour !!!
Também pensando.... a IA ainda não sabe pesquisar direito, acaba sempre dependendo de mais informação, ainda tem muito a aprender. Só não sei dizer se está humana demais ou de menos.