Index: base/applications/regedit/framewnd.c =================================================================== --- base/applications/regedit/framewnd.c (revision 57785) +++ base/applications/regedit/framewnd.c (working copy) @@ -288,20 +288,21 @@ return TRUE; } +#define LOADHIVE_KEYNAMELENGTH 128 + static INT_PTR CALLBACK LoadHive_KeyNameInHookProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static LPWSTR sKey = NULL; - static INT sLength = 0; switch(uMsg) { case WM_INITDIALOG: sKey = (LPWSTR)lParam; - sLength = 128; /* FIXME: Ugly hack! */ + break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: - if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, sLength)) + if(GetDlgItemTextW(hWndDlg, IDC_EDIT_KEY, sKey, LOADHIVE_KEYNAMELENGTH)) return EndDialog(hWndDlg, -1); else return EndDialog(hWndDlg, 0); @@ -348,7 +349,7 @@ OPENFILENAME ofn; WCHAR Caption[128]; LPCWSTR pszKeyPath; - WCHAR xPath[128]; + WCHAR xPath[LOADHIVE_KEYNAMELENGTH]; HKEY hRootKey; WCHAR Filter[1024]; FILTERPAIR filter; @@ -369,7 +370,8 @@ /* now load the hive */ if (GetOpenFileName(&ofn)) { - if(DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd, &LoadHive_KeyNameInHookProc, (LPARAM)xPath)) + if (DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd, + &LoadHive_KeyNameInHookProc, (LPARAM)xPath)) { LONG regLoadResult; Index: base/applications/regedit/listview.c =================================================================== --- base/applications/regedit/listview.c (revision 57785) +++ base/applications/regedit/listview.c (working copy) @@ -127,9 +127,10 @@ linfo = (PLINE_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount); linfo->dwValType = dwValType; linfo->val_len = dwCount; - if(dwCount > 0) + if (dwCount > 0) { memcpy(&linfo[1], ValBuf, dwCount); + linfo->val = &linfo[1]; } linfo->name = _wcsdup(Name); @@ -373,7 +374,10 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { - LINE_INFO*l, *r; + LINE_INFO *l, *r; + INT nCompare; + DWORD dw1, dw2; + DWORDLONG qw1, qw2; UNREFERENCED_PARAMETER(lParamSort); l = (LINE_INFO*)lParam1; @@ -383,11 +387,76 @@ g_columnToSort = 0; if (g_columnToSort == 1 && l->dwValType != r->dwValType) - return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType; + { + /* Sort by type */ + if (g_invertSort) + return (int)r->dwValType - (int)l->dwValType; + else + return (int)l->dwValType - (int)r->dwValType; + } if (g_columnToSort == 2) { - /* FIXME: Sort on value */ + /* Sort by value */ + if (l->dwValType != r->dwValType) + { + if (g_invertSort) + return (int)r->dwValType - (int)l->dwValType; + else + return (int)l->dwValType - (int)r->dwValType; + } + + if (r->val == NULL && l->val == NULL) + return 0; + + if (g_invertSort) + { + if (r->val == NULL) + return -1; + if (l->val == NULL) + return 1; + } + else + { + if (r->val == NULL) + return 1; + if (l->val == NULL) + return -1; + } + + switch(l->dwValType) + { + case REG_DWORD: + dw1 = *(DWORD*)l->val; + dw2 = *(DWORD*)r->val; + if (g_invertSort) + return dw1 > dw2 ? -1 : 1; + else + return dw1 > dw2 ? 1 : -1; + case REG_QWORD: + qw1 = *(DWORDLONG*)l->val; + qw2 = *(DWORDLONG*)r->val; + if (g_invertSort) + return qw1 > qw2 ? -1 : 1; + else + return qw1 > qw2 ? 1 : -1; + } + + if (g_invertSort) + { + nCompare = memcmp(r->val, l->val, min(r->val_len, l->val_len)); + if (nCompare == 0) + nCompare = r->val_len - l->val_len; + } + else + { + nCompare = memcmp(l->val, r->val, min(l->val_len, r->val_len)); + if (nCompare == 0) + nCompare = l->val_len - r->val_len; + } + + return nCompare; } + /* Sort by name */ return g_invertSort ? wcsicmp(r->name, l->name) : wcsicmp(l->name, r->name); }