From 9d6b80b12131808d806564bb72d2ea14d6ee13ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Thu, 28 Aug 2008 16:18:44 +0200 Subject: [PATCH] regedit: Convert value creation to unicode. --- programs/regedit/edit.c | 14 ++++---- programs/regedit/framewnd.c | 71 +++++++++++++++++++------------------ programs/regedit/main.h | 2 +- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/programs/regedit/edit.c b/programs/regedit/edit.c index 1c26baa5ad4..4e4c1ed751b 100644 --- a/programs/regedit/edit.c +++ b/programs/regedit/edit.c @@ -449,27 +449,27 @@ done: return result; } -BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName) +BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName) { LONG lRet = ERROR_SUCCESS; - TCHAR newValue[256]; + WCHAR newValue[256]; DWORD valueDword = 0; BOOL result = FALSE; int valueNum; HKEY hKey; - lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey); + lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey); if (lRet != ERROR_SUCCESS) { error_code_messagebox(hwnd, lRet); return FALSE; } - if (!LoadString(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done; + if (!LoadStringW(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done; /* try to find out a name for the newly create key (max 100 times) */ for (valueNum = 1; valueNum < 100; valueNum++) { - wsprintf(valueName, newValue, valueNum); - lRet = RegQueryValueEx(hKey, valueName, 0, 0, 0, 0); + wsprintfW(valueName, newValue, valueNum); + lRet = RegQueryValueExW(hKey, valueName, 0, 0, 0, 0); if (lRet == ERROR_FILE_NOT_FOUND) break; } if (lRet != ERROR_FILE_NOT_FOUND) { @@ -477,7 +477,7 @@ BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPT goto done; } - lRet = RegSetValueEx(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD)); + lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD)); if (lRet != ERROR_SUCCESS) { error_code_messagebox(hwnd, lRet); goto done; diff --git a/programs/regedit/framewnd.c b/programs/regedit/framewnd.c index dc76eab4f14..2053f70278f 100644 --- a/programs/regedit/framewnd.c +++ b/programs/regedit/framewnd.c @@ -636,15 +636,11 @@ static INT_PTR CALLBACK removefavorite_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM w static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HKEY hKeyRoot = 0; - LPCTSTR keyPath; LPCTSTR valueName; - TCHAR newKey[MAX_NEW_KEY_LEN]; DWORD valueType; int curIndex; BOOL firstItem = TRUE; - keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); - if (LOWORD(wParam) >= ID_FAVORITE_FIRST && LOWORD(wParam) <= ID_FAVORITE_LAST) { HKEY hKey; if (RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey, @@ -683,15 +679,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case ID_EDIT_DELETE: if (GetFocus() == g_pChildWnd->hTreeWnd) { - WCHAR* keyPathW = GetWideString(keyPath); + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (keyPath == 0 || *keyPath == 0) { - MessageBeep(MB_ICONHAND); - } else if (DeleteKey(hWnd, hKeyRoot, keyPathW)) { + MessageBeep(MB_ICONHAND); + } else if (DeleteKey(hWnd, hKeyRoot, keyPath)) { DeleteNode(g_pChildWnd->hTreeWnd, 0); } - HeapFree(GetProcessHeap(), 0, keyPathW); + HeapFree(GetProcessHeap(), 0, keyPath); } else if (GetFocus() == g_pChildWnd->hListWnd) { - WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED); while(curIndex != -1) { WCHAR* valueNameW; @@ -705,7 +701,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; } valueNameW = GetWideString(valueName); - if (!DeleteValue(hWnd, hKeyRoot, keyPathW, valueNameW, curIndex==-1 && firstItem)) + if (!DeleteValue(hWnd, hKeyRoot, keyPath, valueNameW, curIndex==-1 && firstItem)) { HeapFree(GetProcessHeap(), 0, valueNameW); break; @@ -713,8 +709,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) firstItem = FALSE; HeapFree(GetProcessHeap(), 0, valueNameW); } - RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, NULL); - HeapFree(GetProcessHeap(), 0, keyPathW); + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); + HeapFree(GetProcessHeap(), 0, keyPath); } break; case ID_EDIT_MODIFY: @@ -722,10 +718,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LPCWSTR valueNameW = GetValueName(g_pChildWnd->hListWnd); CHAR* valueNameA = GetMultiByteString(valueNameW); WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); - if (ModifyValue(hWnd, hKeyRoot, keyPath, valueNameA)) + CHAR* keyPathA = GetMultiByteString(keyPathW); + if (ModifyValue(hWnd, hKeyRoot, keyPathA, valueNameA)) RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, valueNameW); HeapFree(GetProcessHeap(), 0, valueNameA); HeapFree(GetProcessHeap(), 0, keyPathW); + HeapFree(GetProcessHeap(), 0, keyPathA); break; } case ID_EDIT_FIND: @@ -774,12 +772,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_EDIT_NEW_KEY: { WCHAR newKeyW[MAX_NEW_KEY_LEN]; - WCHAR* keyPathW = GetWideString(keyPath); - if (CreateKey(hWnd, hKeyRoot, keyPathW, newKeyW)) { + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + if (CreateKey(hWnd, hKeyRoot, keyPath, newKeyW)) { if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW)) StartKeyRename(g_pChildWnd->hTreeWnd); } - HeapFree(GetProcessHeap(), 0, keyPathW); + HeapFree(GetProcessHeap(), 0, keyPath); } break; case ID_EDIT_NEW_STRINGVALUE: @@ -795,24 +793,29 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) valueType = REG_DWORD; /* fall through */ create_value: - if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) { - WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); - WCHAR* newKeyW = GetWideString(newKey); - RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, newKeyW); - HeapFree(GetProcessHeap(), 0, keyPathW); - HeapFree(GetProcessHeap(), 0, newKeyW); + { + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR newKey[MAX_NEW_KEY_LEN]; + if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) { + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, newKey); StartValueRename(g_pChildWnd->hListWnd); - /* FIXME: start rename */ - } + /* FIXME: start rename */ + } + HeapFree(GetProcessHeap(), 0, keyPath); + } break; case ID_EDIT_RENAME: - if (keyPath == 0 || *keyPath == 0) { - MessageBeep(MB_ICONHAND); - } else if (GetFocus() == g_pChildWnd->hTreeWnd) { - StartKeyRename(g_pChildWnd->hTreeWnd); - } else if (GetFocus() == g_pChildWnd->hListWnd) { - StartValueRename(g_pChildWnd->hListWnd); - } + { + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + if (keyPath == 0 || *keyPath == 0) { + MessageBeep(MB_ICONHAND); + } else if (GetFocus() == g_pChildWnd->hTreeWnd) { + StartKeyRename(g_pChildWnd->hTreeWnd); + } else if (GetFocus() == g_pChildWnd->hListWnd) { + StartValueRename(g_pChildWnd->hListWnd); + } + HeapFree(GetProcessHeap(), 0, keyPath); + } break; case ID_REGISTRY_PRINTERSETUP: /*PRINTDLG pd;*/ @@ -856,10 +859,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case ID_VIEW_REFRESH: { - WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); RefreshTreeView(g_pChildWnd->hTreeWnd); - RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, NULL); - HeapFree(GetProcessHeap(), 0, keyPathW); + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); + HeapFree(GetProcessHeap(), 0, keyPath); } break; /*case ID_OPTIONS_TOOLBAR:*/ diff --git a/programs/regedit/main.h b/programs/regedit/main.h index af1e9bb1e4d..aacacc68531 100644 --- a/programs/regedit/main.h +++ b/programs/regedit/main.h @@ -141,7 +141,7 @@ extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mod /* edit.c */ extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR newKeyName); -extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName); +extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName); extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName); extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath); extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox);