On Fri, Mar 17, 2017 at 04:22:20AM +0000, Alistair Leslie-Hughes wrote:
v2 - Support Usage Count. v3 - Write key when not zero. v4 - Only Close key when it was successfully opened.
Signed-off-by: Alistair Leslie-Hughes leslie_alistair@hotmail.com
dlls/odbccp32/odbccp32.c | 69 +++++++++++++++++++++++++++++++++++++++++----- dlls/odbccp32/tests/misc.c | 4 +-- 2 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index 037a2a9..5e70a9d 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -1132,22 +1132,77 @@ BOOL WINAPI SQLRemoveDefaultDataSource(void) return FALSE; }
-BOOL WINAPI SQLRemoveDriverW(LPCWSTR lpszDriver, BOOL fRemoveDSN,
LPDWORD lpdwUsageCount)
+BOOL WINAPI SQLRemoveDriverW(LPCWSTR drivername, BOOL remove_dsn, LPDWORD usage_count) {
- HKEY hkey;
- DWORD usagecount = 1;
- clear_errors();
- FIXME("%s %d %p\n", debugstr_w(lpszDriver), fRemoveDSN, lpdwUsageCount);
- if (lpdwUsageCount) *lpdwUsageCount = 1;
- TRACE("%s %d %p\n", debugstr_w(drivername), remove_dsn, usage_count);
- if (RegOpenKeyW(HKEY_LOCAL_MACHINE, odbcini, &hkey) == ERROR_SUCCESS)
- {
HKEY hkeydriver;
if (RegOpenKeyW(hkey, drivername, &hkeydriver) == ERROR_SUCCESS)
{
DWORD size, type;
size = sizeof(usagecount);
RegGetValueA(hkeydriver, NULL, "UsageCount", RRF_RT_DWORD, &type, &usagecount, &size);
TRACE("Usage count %d\n", usagecount);
RegCloseKey(hkeydriver);
}
if (usagecount)
usagecount--;
if (!usagecount)
{
if (RegDeleteKeyW(hkey, drivername) != ERROR_SUCCESS)
ERR("Failed to delete registry key: %s\n", debugstr_w(drivername));
if (RegOpenKeyW(hkey, odbcdrivers, &hkeydriver) == ERROR_SUCCESS)
{
if(RegDeleteValueW(hkeydriver, drivername) != ERROR_SUCCESS)
ERR("Failed to delete registry value: %s\n", debugstr_w(drivername));
RegCloseKey(hkeydriver);
}
}
else
{
if (RegOpenKeyW(hkey, drivername, &hkeydriver) == ERROR_SUCCESS)
{
if (RegSetValueExA(hkeydriver, "UsageCount", 0, REG_DWORD, (BYTE*)&usagecount, sizeof(usagecount)) != ERROR_SUCCESS)
ERR("Failed to write registry UsageCount key\n");
RegCloseKey(hkeydriver);
}
}
RegCloseKey(hkey);
- }
It should be possible to do this without needing to open the drivername key twice.
Huw.