DaRam Posted June 24, 2008 Share Posted June 24, 2008 Appreciate Help with Translating this to an AutoIt FunctionHere is the working VB Function GetDriversList():expandcollapse popupConst SQL_SUCCESS As Long = 0 Const SQL_FETCH_NEXT As Long = 1 Private Declare Function SQLDrivers Lib "ODBC32.DLL" ( _ ByVal hEnv As Long, _ ByVal fDirection As Integer, _ ByVal szDriverDesc As String, _ ByVal cbDriverDescMax As Integer, _ ByRef pcbDriverDesc As Integer, _ ByVal szDriverAttributes As String, _ ByVal cbDrvrAttrMax As Integer, _ ByRef pcbDrvrAttr As Integer) As Integer Private Declare Function SQLDataSources Lib "ODBC32.DLL" ( _ ByVal hEnv&, _ ByVal fDirection%, _ ByVal szDSN$, _ ByVal cbDSNMax%, _ pcbDSN%, _ ByVal szDescription$, _ ByVal cbDescriptionMax%, _ pcbDescription%) As Integer Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&) Public Function GetDriversList() As String ' Returns a Comma Seperated List of Installed Database Drivers Dim I As Integer Dim sDriverDescription As String * 1024 Dim sDriverAttribute As String * 1024 Dim sDriverName As String 'Dim sDriverAttrib As String Dim iDriverDescriptionLength As Integer Dim iDriverAttributeLength As Integer Dim lHenv As Long 'handle to the environment Dim sGetDriversList As String On Error Resume Next ' Get List of Installed Database Drivers If SQLAllocEnv(lHenv) <> -1 Then Do Until I <> SQL_SUCCESS sDriverDescription = Space$(1024) sDriverAttribute = Space$(1024) I = SQLDrivers(lHenv, SQL_FETCH_NEXT, sDriverDescription, 1024, iDriverDescriptionLength, sDriverAttribute, 1024, iDriverAttributeLength) If I = SQL_SUCCESS Then sDriverName = Left$(sDriverDescription, iDriverDescriptionLength) 'sDriverAttrib = Left$(sDriverAttribute, iDriverAttributeLength - 1) 'Debug.Print "Driver=" & sDriverName & " (" & sDriverAttrib & ")" sGetDriversList = sGetDriversList & sDriverName & "," End If Loop End If If Right(sGetDriversList, 1) = "," Then sGetDriversList = Left(sGetDriversList, Len(sGetDriversList) - 1) GetDriversList = sGetDriversList End FunctionHere is where I've gotten to (With help from this Post):Func OdbcDrivers() ; Returns List of Pipe (|) Delimited Installed ODBC Drivers Local Const $SQL_SUCCESS = 0 Local Const $SQL_FETCH_NEXT = 1 Local $OdbcDrivers = "" Local $OdbcDll = DllOpen("odbc32.DLL") ; Open ODBC Driver Manager Local $AllocBuffer = DllStructCreate("udword") Local $EnvironHandle ; Enviroment Descriptor Local $Buffer1 = DllStructCreate("char[1024]") Local $Buffer2 = DllStructCreate("long") Local $Buffer3 = DllStructCreate("char[1024]") Local $Buffer4 = DllStructCreate("long") Dim $result[9] $result[6]="ALPHA" $Result = DllCall($OdbcDll, "short", "SQLAllocEnv", "long", DllStructGetPtr($AllocBuffer)) $EnvironHandle = DllStructGetData($AllocBuffer,1) $AllocBuffer = 0 ; Release This While 1 ; $Result <> SQL_SUCCESS $Result = DllCall($OdbcDll, "int", "SQLDriversW", "long", $EnvironHandle, "long", $SQL_FETCH_NEXT, _ "wstr", DllStructGetPtr($Buffer1), "long", 255, "long", _ DllStructGetPtr($Buffer1), "wstr", DllStructGetPtr($Buffer2), "long", 255, "long", DllStructGetPtr($Buffer3) _ ) If StringIsDigit($result[6]) = True then ExitLoop ; I think the Problem is here? $OdbcDrivers = $OdbcDrivers & "|" & $Result[3] Wend $Result = 0 DllClose($OdbcDll) If StringLeft($OdbcDrivers, 1) = "|" Then $OdbcDrivers = StringMid($OdbcDrivers, 2) Return $OdbcDrivers EndFuncMy Problem is I do not know if the Dll Call to 'SQLDrivers' function (in odbc32.dll) is working since it never exits the While Loop Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 24, 2008 Share Posted June 24, 2008 Appreciate Help with Translating this to an AutoIt Function Here is the working VB Function GetDriversList(): My Problem is I do not know if the Dll Call to 'SQLDrivers' function (in odbc32.dll) is working since it never exits the While Loop The string when it's done is Hex with "0x" in it. That's why StringIsDigit fails. Try this: While 1; $Result <> SQL_SUCCESS $Result = DllCall($OdbcDll, "int", "SQLDriversW", "long", $EnvironHandle, "long", $SQL_FETCH_NEXT, _ "wstr", DllStructGetPtr($Buffer1), "long", 255, "long", _ DllStructGetPtr($Buffer1), "wstr", DllStructGetPtr($Buffer2), "long", 255, "long", DllStructGetPtr($Buffer3) _ ) If Number($result[6]) Then ExitLoop; <======= Change $OdbcDrivers = $OdbcDrivers & "|" & $Result[3] Wend Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
DaRam Posted June 25, 2008 Author Share Posted June 25, 2008 If Number($result[6]) Then ExitLoop; <======= ChangeThanks, I'll take a look at it when I'm back on my Dev PC. But, being presumptive/premptive - were you able to get a string with the Drivers back from the fn.? I am not sure if I have implemented the DLL call properly. Link to comment Share on other sites More sharing options...
DaRam Posted June 25, 2008 Author Share Posted June 25, 2008 That worked. Thanks PsaltyDS. The string when it's done is Hex with "0x" in it. That's why StringIsDigit fails. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 25, 2008 Share Posted June 25, 2008 Thanks, I'll take a look at it when I'm back on my Dev PC. But, being presumptive/premptive - were you able to get a string with the Drivers back from the fn.? I am not sure if I have implemented the DLL call properly. This works for me (updated a little): #include <Array.au3> $avRET = OdbcDrivers() _ArrayDisplay($avRET, "ODBC Drivers") Func OdbcDrivers() ; Returns List of Pipe (|) Delimited Installed ODBC Drivers Local Const $SQL_SUCCESS = 0 Local Const $SQL_FETCH_NEXT = 1 Local $OdbcDrivers = "" Local $OdbcDll = DllOpen("odbc32.DLL"); Open ODBC Driver Manager Local $AllocBuffer = DllStructCreate("udword") Local $EnvironHandle; Enviroment Descriptor Local $Buffer1 = DllStructCreate("char[1024]") Local $Buffer2 = DllStructCreate("long") Local $Buffer3 = DllStructCreate("char[1024]") Local $Buffer4 = DllStructCreate("long") Local $result = DllCall($OdbcDll, "short", "SQLAllocEnv", "long", DllStructGetPtr($AllocBuffer)) $EnvironHandle = DllStructGetData($AllocBuffer, 1) $AllocBuffer = 0; Release This While 1; $Result <> SQL_SUCCESS $result = DllCall($OdbcDll, "int", "SQLDriversW", "long", $EnvironHandle, "long", $SQL_FETCH_NEXT, _ "wstr", DllStructGetPtr($Buffer1), "long", 255, "long", DllStructGetPtr($Buffer1), _ "wstr", DllStructGetPtr($Buffer2), "long", 255, "long", DllStructGetPtr($Buffer3)) ConsoleWrite("Debug: $result[6] = " & $result[6] & @LF) ConsoleWrite("Debug: $result[3] = " & $result[3] & @LF & @LF) If Number($result[6]) Then ExitLoop $OdbcDrivers &= $result[3] & Chr(1) WEnd DllClose($OdbcDll) Return StringSplit(StringTrimRight($OdbcDrivers, 1), chr(1)) EndFunc ;==>OdbcDrivers Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now