--- mstools/samples/registry/monkey.c 2018/08/09 18:20:41 1.1.1.1 +++ mstools/samples/registry/monkey.c 2018/08/09 18:23:40 1.1.1.3 @@ -1,3 +1,14 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + /*************************************************************************\ * * PROGRAM: Monkey: the Registry Monkey Utility. @@ -7,6 +18,7 @@ \*************************************************************************/ +#define STRICT #include #include #include @@ -44,7 +56,7 @@ int APIENTRY WinMain (HINSTANCE hInstanc UNREFERENCED_PARAMETER( hPrevInstance ); hInst = hInstance; - hHeap = HeapCreate (HEAP_SERIALIZE, 0, 0); + hHeap = HeapCreate (0, 0, 0); retCode = DialogBox ((HANDLE)hInst, (LPCSTR)"MonkeyDlg", NULL, (DLGPROC)MonkeyDlgProc); @@ -186,11 +198,6 @@ int APIENTRY MonkeyDlgProc (HWND hDlg, W } return (0); - case IDB_PRINT: - - MessageBox (NULL, "Sorry, due to last minute changes in the system, this feature was removed. It may be replaced in a future version.", - "Last Minute Note.", MB_OK); - return (0); case IDB_NEXT: // Get the index of the cursor selection @@ -365,15 +372,13 @@ int APIENTRY MonkeyDlgProc (HWND hDlg, W * one indicated by the ListBox selection. * \************************************************************************/ -VOID EnumerateLevel (HWND hDlg, LPTSTR NameLBSelect, - LPTSTR RegPath, HANDLE *hKeyRoot) + VOID EnumerateLevel (HWND hDlg, LPTSTR NameLBSelect, + LPTSTR RegPath, HKEY *hKeyRoot) { - HANDLE hKey; - HDC hDC; + HKEY hKey; DWORD retCode; CHAR Buf[80]; - RECT rect; if (*hKeyRoot) @@ -392,7 +397,8 @@ VOID EnumerateLevel (HWND hDlg, LPTSTR N // Registry path to get an open handle // to the child key you want to // enumerate. - retCode = RegOpenKeyEx (*hKeyRoot, RegPath, + retCode = RegOpenKeyEx (*hKeyRoot, + RegPath, 0, KEY_ENUMERATE_SUB_KEYS | KEY_EXECUTE | @@ -439,12 +445,12 @@ VOID EnumerateLevel (HWND hDlg, LPTSTR N RegCloseKey (hKey); // Close the key handle. - rect.top = 0; rect.left = 5; rect.right = 1200; rect.bottom = 25; - hDC = GetDC (hDlg); - FillRect (hDC, &rect, GetStockObject(WHITE_BRUSH)); - TextOut (hDC, 5, 5, RegPath, strlen(RegPath)); - ReleaseDC (hDlg, hDC); - +// rect.top = 0; rect.left = 5; rect.right = 1200; rect.bottom = 25; +// hDC = GetDC (hDlg); +// FillRect (hDC, &rect, GetStockObject(WHITE_BRUSH)); +// TextOut (hDC, 5, 5, RegPath, strlen(RegPath)); +// ReleaseDC (hDlg, hDC); + SetDlgItemText (hDlg, IDE_TEXTOUT, RegPath); } @@ -574,7 +580,7 @@ VOID QueryKey (HWND hDlg, HANDLE hKey) VOID DisplayKeyData (HWND hDlg, CHAR *RegPath, HANDLE hKeyRoot) { - HANDLE hKey; + HKEY hKey; DWORD dwLBIndex; CHAR Buf[LINE_LEN]; CHAR ValueName[MAX_VALUE_NAME]; @@ -647,7 +653,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re MessageBox (hDlg, Buf, "", MB_OK); } - bData = HeapAlloc (hHeap, dwcMaxValueData); + bData = HeapAlloc (hHeap, 0, dwcMaxValueData); cbData = dwcMaxValueData; @@ -662,7 +668,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re bData, // Data buffer. &cbData); // Size of data buffer. - if (retCode) + if (retCode != ERROR_SUCCESS) { if (dwType < REG_FULL_RESOURCE_DESCRIPTOR) @@ -696,7 +702,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re case REG_SZ: SetDlgItemText (hDlg, IDE_VALUE1, "REG_SZ: A null-terminated Unicode string."); - outBuf = HeapAlloc (hHeap, cbData + 2); + outBuf = HeapAlloc (hHeap, 0, cbData + 2); *outBuf = '\0'; strcat (outBuf, "\""); @@ -704,12 +710,12 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re strcat (outBuf, "\""); SetDlgItemText (hDlg, IDE_VALUE2, outBuf); - HeapFree (hHeap, outBuf); + HeapFree (hHeap, 0, outBuf); break; case REG_EXPAND_SZ: SetDlgItemText (hDlg, IDE_VALUE1, "REG_EXPAND_SZ: A String referencing environment variables i.e. PATH."); - outBuf = HeapAlloc (hHeap, cbData + 2); + outBuf = HeapAlloc (hHeap, 0, cbData + 2); *outBuf = '\0'; strcat (outBuf, "\""); @@ -717,7 +723,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re strcat (outBuf, "\""); SetDlgItemText (hDlg, IDE_VALUE2, outBuf); - HeapFree (hHeap, outBuf); + HeapFree (hHeap, 0, outBuf); break; case REG_BINARY: @@ -725,7 +731,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re SetDlgItemText (hDlg, IDE_VALUE1, "REG_BINARY: Freeform binary data."); SetCursor (LoadCursor (NULL, IDC_WAIT)); - BinaryStrBuf = HeapAlloc (hHeap, (3 * cbData) + 1); + BinaryStrBuf = HeapAlloc (hHeap, 0, (3 * cbData) + 1); if (BinaryStrBuf) { *BinaryStrBuf = '\0'; @@ -743,19 +749,19 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re "Debug: DisplayKeyData", MB_OK); } SetDlgItemText (hDlg, IDL_LISTBOX2, BinaryStrBuf); - HeapFree (hHeap, BinaryStrBuf); + HeapFree (hHeap, 0, BinaryStrBuf); SetCursor (LoadCursor (NULL, IDC_ARROW)); break; case REG_DWORD: SetDlgItemText (hDlg, IDE_VALUE1, "REG_DWORD: A 32 bit number."); - SetDlgItemInt (hDlg, IDE_VALUE2, *bData, TRUE); + SetDlgItemInt (hDlg, IDE_VALUE2, *(UINT *)bData, FALSE); break; case REG_DWORD_BIG_ENDIAN: SetDlgItemText (hDlg, IDE_VALUE1, "REG_DWORD_BIG_ENDIAN: A 32 bit number in big endian format."); - SetDlgItemInt (hDlg, IDE_VALUE2, *bData, TRUE); + SetDlgItemInt (hDlg, IDE_VALUE2, *(UINT *)bData, TRUE); break; case REG_LINK: @@ -774,7 +780,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re cStrLen+=4; // Add room for two quotes and two // spaced per string. - outBuf = HeapAlloc (hHeap, cbData + cStrLen); + outBuf = HeapAlloc (hHeap, 0, cbData + cStrLen); ptr = bData; // Set ptr to beginning of buffer. *outBuf = '\0'; // Initialize output string. @@ -791,7 +797,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re SetDlgItemText (hDlg, IDE_VALUE2, outBuf); SetCursor (LoadCursor (NULL, IDC_ARROW)); - HeapFree (hHeap, outBuf); // free output string. + HeapFree (hHeap, 0, outBuf); // free output string. break; @@ -802,7 +808,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re // different release. SetDlgItemText (hDlg, IDE_VALUE1, "REG_RESOURCE_LIST: A device-driver resource list."); - BinaryStrBuf = HeapAlloc (hHeap, (3 * cbData) + 1); + BinaryStrBuf = HeapAlloc (hHeap, 0, (3 * cbData) + 1); if (BinaryStrBuf) { *BinaryStrBuf = '\0'; @@ -820,7 +826,7 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re "Debug: DisplayKeyData", MB_OK); } SetDlgItemText (hDlg, IDL_LISTBOX2, BinaryStrBuf); - HeapFree (hHeap, BinaryStrBuf); + HeapFree (hHeap, 0, BinaryStrBuf); break; @@ -839,5 +845,5 @@ VOID DisplayKeyData (HWND hDlg, CHAR *Re } // end switch - HeapFree (hHeap, bData); + HeapFree (hHeap, 0, bData); }