From c364302037cb157366c48d9c9e86c86c758a24d8 Mon Sep 17 00:00:00 2001 From: Stefan Persson Date: Tue, 4 Oct 2011 11:02:41 +0000 Subject: [PATCH] Fix to allow storage of more than 127 devices in Windows. Closes #95 --- telldus-core/service/SettingsWinRegistry.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/telldus-core/service/SettingsWinRegistry.cpp b/telldus-core/service/SettingsWinRegistry.cpp index d5bb1473..939f6152 100644 --- a/telldus-core/service/SettingsWinRegistry.cpp +++ b/telldus-core/service/SettingsWinRegistry.cpp @@ -120,28 +120,16 @@ int Settings::getNextDeviceId() const { if(lnExists == ERROR_SUCCESS){ DWORD dwLength; - char *Buff = new char[intMaxRegValueLength]; + DWORD nResult(0); - long lngStatus = RegQueryValueEx(hk, L"LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); - - if(lngStatus == ERROR_MORE_DATA){ - //The buffer is to small, recreate it - delete Buff; - Buff = new char[dwLength]; - lngStatus = RegQueryValueEx(hk, L"LastUsedId", NULL, NULL, (LPBYTE)Buff, &dwLength); - } + long lngStatus = RegQueryValueEx(hk, L"LastUsedId", NULL, NULL, reinterpret_cast(&nResult), &dwLength); //(LPBYTE)Buff, &dwLength); if(lngStatus == ERROR_SUCCESS){ - - int intLast = (int)Buff[0]; - intReturn = intLast + 1; + intReturn = nResult + 1; } else { intReturn = 1; } - delete Buff; - DWORD dwVal = intReturn; - RegSetValueEx (hk, L"LastUsedId", 0L, REG_DWORD, (CONST BYTE*) &dwVal, sizeof(DWORD)); }