From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
Use ConfigMode to determine where to look for the key. --- dlls/odbccp32/odbccp32.c | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index 6c37c0a5265..d62955d7929 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -1813,8 +1813,9 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry LPCWSTR lpszString, LPCWSTR lpszFilename) { static const WCHAR empty[] = {0}; - LONG ret; - HKEY hkey; + LONG ret = ERROR_FILE_NOT_FOUND; + HKEY hkey, hrootkey; + WCHAR *regpath;
clear_errors(); TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry), @@ -1826,7 +1827,42 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry return FALSE; }
- if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) == ERROR_SUCCESS) + regpath = malloc ( (wcslen(L"Software\ODBC\") + wcslen(lpszFilename) + wcslen(L"\") + + wcslen(lpszSection) + 1) * sizeof(WCHAR)); + if (!regpath) + { + push_error(ODBC_ERROR_OUT_OF_MEM, odbc_error_out_of_mem); + return FALSE; + } + wcscpy(regpath, L"Software\ODBC\"); + wcscat(regpath, lpszFilename); + wcscat(regpath, L"\"); + wcscat(regpath, lpszSection); + + /* Check for an existing key first before writing a new one */ + if (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_USER_DSN) + { + ret = RegOpenKeyW(HKEY_CURRENT_USER, regpath, &hkey); + } + + if (!hkey && (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_SYSTEM_DSN)) + { + ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, regpath, &hkey); + } + + hrootkey = config_mode == ODBC_SYSTEM_DSN ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + free(regpath); + + if (ret == ERROR_SUCCESS) + { + if(lpszString) + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR)); + else + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)empty, sizeof(empty)); + RegCloseKey(hkey); + } + else if ((ret = RegCreateKeyW(hrootkey, odbcW, &hkey)) == ERROR_SUCCESS) { HKEY hkeyfilename;