I need to create an ODBC driver during the installation process. I want to use the SQLConfigDriver function from the odbccp32.dll file.
The function syntax is the following :
SummarySo I decided to create a macro to execute this function with the system.dll.
SQLConfigDriver loads the appropriate driver setup DLL and calls the ConfigDriver function.
Syntax
BOOL SQLConfigDriver (
HWND hwndParent,
WORD fRequest,
LPCSTR lpszDriver,
LPCSTR lpszArgs,
LPSTR lpszMsg,
WORD cbMsgMax,
WORD* pcbMsgOut);
Arguments
hwndParent [Input]
Parent window handle. The function will not display any dialog boxes if the handle is null.
fRequest [Input]
Type of request. fRequest must contain one of the following values:
ODBC_CONFIG_DRIVER: Changes the connection pooling timeout used by the driver.
ODBC_INSTALL_DRIVER: Installs a new driver.
ODBC_REMOVE_DRIVER: Removes an existing driver.
This option can also be driver-specific, in which case the fRequest for the first option must start from ODBC_CONFIG_DRIVER_MAX+1. The fRequest for any additional option must also start from a value greater than ODBC_CONFIG_DRIVER_MAX+1.
lpszDriver [Input]
The name of the driver as registered in the system information.
lpszArgs [Input]
A null-terminated string containing arguments for a driver-specific fRequest.
lpszMsg [Output]
A null-terminated string containing an output message from the driver setup.
cbMsgMax [Input]
Length of lpszMsg.
pcbMsgOut [Output]
Total number of bytes available to return in lpszMsg. If the number of bytes available to return is greater than or equal to cbMsgMax, the output message in lpszMsg is truncated to cbMsgMax minus the null-termination character. The pcbMsgOut argument can be a null pointer.
Returns
The function returns TRUE if it is successful, FALSE if it fails.
The code of the macro is the following :
And I'm calling it this way in the main section of the installer :!macro LIBODBC_CONFIG_ODBC_DRIVER
!ifdef LIBODBC_UNINST_SUPPORT
!undef UnODBCConfigDriver
!define UnODBCConfigDriver "!insertmacro LIBODBC_CONFIG_ODBC_DRIVER_UnCall"
Function un.ODBCConfigDriver
!else
!undef ODBCConfigDriver
!define ODBCConfigDriver "!insertmacro LIBODBC_CONFIG_ODBC_DRIVER_Call"
Function ODBCConfigDriver
!endif
; Saves variables, gets the function parameters
Exch $R0 ; input : LOGFILE
Exch 2
Exch $R1 ; input : ODBCDriverName
Exch
Exch $R2 ; input : Type of Request
Push $R3 ; output : TRUE/FALSE
!ifdef LIBODBC_UNINST_SUPPORT
${UnPrint} ""
${UnPrint} "--------------------------------------"
${UnPrint} "--------------------------------------"
${UnPrint} "-- ConfigAnODBCDriver"
${UnPrint} "ODBCDriverName : $R1"
${UnPrint} "Type of Request : $R2"
${UnPrint} "--------------------------------------"
!else
${Print} ""
${Print} "--------------------------------------"
${Print} "--------------------------------------"
${Print} "-- ConfigAnODBCDriver"
${Print} "ODBCDriverName : $R1"
${Print} "Type of Request : $R2"
${Print} "--------------------------------------"
!endif
${Select} "$R2"
${Case} "ODBC_INSTALL_DRIVER"
StrCpy $R2 1
${Case} "ODBC_REMOVE_DRIVER"
StrCpy $R2 2
${Case} "ODBC_CONFIG_DRIVER"
StrCpy $R2 3
${EndSelect}
SetPluginUnload alwaysoff
SetOutPath $PLUGINSDIR ; go to temporary directory
;File "$SYSDIR\odbccp32.dll" ; copy dll there
File "C:\WINDOWS\system32\odbccp32.dll"
dumpstate::debug
System::Call 'odbccp32.dll::SQLConfigDriver \
(i 0, i $R2, t "$R1", t "", t "", t "", i 0, i 0) i'
dumpstate::debug
SetPluginUnload manual ; let the installer unload the System dll
System::Free 0
;WriteIniStr "$R0" "ODBC.data" "ODBC_DRIVER_IS_CONFIGURED" "$R3"
!ifdef LIBODBC_UNINST_SUPPORT
${UnPrint} "ODBCDriverConfigured : $R3"
${UnPrint} "--------------------------------------"
!else
${Print} "ODBCDriverConfigured : $R3"
${Print} "--------------------------------------"
!endif
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
!macroend
!macro LIBODBC_CONFIG_ODBC_DRIVER_Call LOGFILE ODBCDRIVERNAME FREQUEST
!echo `$ {ODBCDriverExists} "${LOGFILE}" "${ODBCDRIVERNAME}" "${FREQUEST}"$\r$\n`
Push `${ODBCDRIVERNAME}`
Push `${FREQUEST}`
Push `${LOGFILE}`
Call ODBCConfigDriver
!macroend
!macro LIBODBC_CONFIG_ODBC_DRIVER_UnCall LOGFILE ODBCDRIVERNAME FREQUEST
!echo `$ {UnODBCDriverExists} "${LOGFILE}" "${ODBCDRIVERNAME} "${FREQUEST}""$\r$\n`
Push `${ODBCDRIVERNAME}`
Push `${FREQUEST}`
Push `${LOGFILE}`
Call un.ODBCConfigDriver
!macroend
${ODBCConfigDriver} "$PLUGINSDIR\${UNINSTALL_INI_FILE}" \
"${ODBC_DRIVER_NAME}" "ODBC_INSTALL_DRIVER"Mains problems are that I don't known how to get the output from the dll call (0 or 1) and that it doesn't seems to work ://.I try to find documentation about the use of dll with system.dll but i don't find anything interresting (or helping me with my problem).
Thanks for your help,
Geoffrey