├── 01-ErrorShow ├── 01-ErrorShow.vcproj ├── 01-ErrorShow.vcxproj ├── ErrorShow.cpp ├── ErrorShow.ico ├── ErrorShow.rc └── Resource.h ├── 03-Singleton ├── 03-Singleton.vcproj ├── 03-Singleton.vcxproj ├── Resource.h ├── Singleton.cpp ├── Singleton.ico └── Singleton.rc ├── 04-ProcessInfo ├── 04-ProcessInfo.vcproj ├── 04-ProcessInfo.vcxproj ├── ProcessInfo.cpp ├── ProcessInfo.ico ├── ProcessInfo.rc └── Resource.h ├── 05-JobLab ├── 05-JobLab.vcproj ├── 05-JobLab.vcxproj ├── Job.h ├── JobLab.cpp ├── JobLab.ico ├── JobLab.rc └── Resource.h ├── 07-SchedLab ├── 07-SchedLab.vcproj ├── 07-SchedLab.vcxproj ├── Resource.h ├── SchedLab.cpp ├── SchedLab.ico └── SchedLab.rc ├── 08-Queue ├── 08-Queue.vcproj ├── 08-Queue.vcxproj ├── Queue.cpp ├── Queue.h ├── Queue.ico ├── Queue.rc └── Resource.h ├── 08-UserSyncCompare ├── 08-UserSyncCompare.vcproj ├── 08-UserSyncCompare.vcxproj └── UserSyncCompare.cpp ├── 09-BadLock ├── 09-BadLock.vcproj ├── 09-BadLock.vcxproj └── BadLock.cpp ├── 09-Handshake ├── 09-Handshake.vcproj ├── 09-Handshake.vcxproj ├── Handshake.cpp ├── Handshake.ico ├── Handshake.rc └── Resource.h ├── 09-LockCop ├── 09-LockCop.vcproj ├── 09-LockCop.vcxproj ├── ChainParser.h ├── LockCop.cpp ├── LockCop.ico ├── LockCop.rc └── Resource.h ├── 09-Queue ├── 09-Queue.vcproj ├── 09-Queue.vcxproj ├── Queue.cpp ├── Queue.ico ├── Queue.rc └── Resource.h ├── 10-FileCopy ├── 10-FileCopy.vcproj ├── 10-FileCopy.vcxproj ├── FileCopy.cpp ├── FileCopy.ico ├── FileCopy.rc └── Resource.h ├── 11-Batch ├── 11-Batch.vcproj ├── 11-Batch.vcxproj ├── Batch.cpp ├── Batch.h ├── Batch.ico ├── Batch.rc └── Resource.h ├── 11-PrivateBatch ├── 11-PrivateBatch.vcproj ├── 11-PrivateBatch.vcxproj ├── PrivateBatch.cpp ├── PrivateBatch.h ├── PrivateBatch.ico ├── PrivateBatch.rc └── Resource.h ├── 11-TimedMsgBox ├── 11-TimedMsgBox.vcproj ├── 11-TimedMsgBox.vcxproj ├── Resource.h ├── TimedMsgBox.cpp ├── TimedMsgBox.ico └── TimedMsgBox.rc ├── 12-Counter ├── 12-Counter.vcproj ├── 12-Counter.vcxproj ├── Counter.cpp ├── Counter.ico ├── Counter.rc └── Resource.h ├── 14-SysInfo ├── 14-SysInfo.vcproj ├── 14-SysInfo.vcxproj ├── Resource.h ├── SysInfo.cpp ├── SysInfo.ico └── SysInfo.rc ├── 14-VMMap ├── 14-VMMap.vcproj ├── 14-VMMap.vcxproj ├── Resource.h ├── VMMap.cpp ├── VMMap.ico ├── VMMap.rc ├── VMQuery.cpp └── VMQuery.h ├── 14-VMStat ├── 14-VMStat.vcproj ├── 14-VMStat.vcxproj ├── Resource.h ├── VMStat.cpp ├── VMStat.ico └── VMStat.rc ├── 15-AWE ├── 15-AWE.exe.manifest ├── 15-AWE.vcproj ├── 15-AWE.vcxproj ├── AWE.cpp ├── AWE.ico ├── AWE.rc ├── AddrWindow.h └── Resource.h ├── 15-MemReset ├── 15-MemReset.vcproj ├── 15-MemReset.vcxproj ├── MemReset.cpp ├── MemReset.ico ├── MemReset.rc └── Resource.h ├── 15-VMAlloc ├── 15-VMAlloc.vcproj ├── 15-VMAlloc.vcxproj ├── Resource.h ├── VMAlloc.cpp ├── VMAlloc.ico └── VMAlloc.rc ├── 16-Summation ├── 16-Summation.vcproj ├── 16-Summation.vcxproj ├── Resource.h ├── Summation.cpp ├── Summation.ico └── Summation.rc ├── 17-AppInst ├── 17-AppInst.vcproj ├── 17-AppInst.vcxproj ├── AppInst.cpp ├── AppInst.ico ├── AppInst.rc └── Resource.h ├── 17-FileRev ├── 17-FileRev.vcproj ├── 17-FileRev.vcxproj ├── FileRev.cpp ├── FileRev.ico ├── FileRev.rc └── Resource.h ├── 17-MMFShare ├── 17-MMFShare.vcproj ├── 17-MMFShare.vcxproj ├── MMFShare.cpp ├── MMFShare.ico ├── MMFShare.rc └── Resource.h ├── 17-MMFSparse ├── 17-MMFSparse.vcproj ├── 17-MMFSparse.vcxproj ├── MMFSparse ├── MMFSparse.cpp ├── MMFSparse.ico ├── MMFSparse.rc ├── Resource.h └── SparseStream.h ├── 20-DelayLoadApp ├── 20-DelayLoadApp.vcproj ├── 20-DelayLoadApp.vcxproj ├── DelayLoadApp.cpp ├── DelayLoadApp.ico ├── DelayLoadApp.rc └── Resource.h ├── 20-DelayLoadLib ├── 20-DelayLoadLib.vcproj ├── 20-DelayLoadLib.vcxproj ├── DelayLoadLib.cpp └── DelayLoadLib.h ├── 22-DIPS ├── 22-DIPS.vcproj ├── 22-DIPS.vcxproj ├── DIPS.cpp ├── DIPS.ico ├── DIPS.rc └── Resource.h ├── 22-DIPSLib ├── 22-DIPSLib.vcproj ├── 22-DIPSLib.vcxproj ├── DIPSLib.cpp ├── DIPSLib.h ├── DIPSLib.rc └── Resource.h ├── 22-ImgWalk ├── 22-ImgWalk.vcproj ├── 22-ImgWalk.vcxproj └── ImgWalk.cpp ├── 22-InjLib ├── 22-InjLib.vcproj ├── 22-InjLib.vcxproj ├── InjLib.cpp ├── InjLib.ico ├── InjLib.rc └── Resource.h ├── 22-LastMsgBoxInfo ├── 22-LastMsgBoxInfo.vcproj ├── 22-LastMsgBoxInfo.vcxproj ├── LastMsgBoxInfo.cpp ├── LastMsgBoxInfo.ico ├── LastMsgBoxInfo.rc └── Resource.h ├── 22-LastMsgBoxInfoLib ├── 22-LastMsgBoxInfoLib.vcproj ├── 22-LastMsgBoxInfoLib.vcxproj ├── APIHook.cpp ├── APIHook.h ├── LastMsgBoxInfoLib.cpp └── LastMsgBoxInfoLib.h ├── 23-SEHTerm ├── 23-SEHTerm.vcproj ├── 23-SEHTerm.vcxproj ├── Resource.h ├── SEHTerm.cpp ├── SEHTerm.ico └── SEHTerm.rc ├── 25-Spreadsheet ├── 25-Spreadsheet.vcproj ├── 25-Spreadsheet.vcxproj ├── Resource.h ├── Spreadsheet.cpp ├── Spreadsheet.ico ├── Spreadsheet.rc └── VMArray.h ├── 26-CustomizedWER ├── 26-CustomizedWER.vcproj ├── 26-CustomizedWER.vcxproj ├── CustomizedWER.cpp ├── CustomizedWER.h ├── CustomizedWER.ico ├── CustomizedWER.rc └── Resource.h ├── Clean.bat ├── CommonFiles ├── CmnHdr.h ├── EnsureCleanup.h ├── IoCompletionPort.h ├── Toolhelp.h └── WaitChainTraversal.h ├── README.md ├── Windows via C++.sln └── windows-via-cplusplus-code.zip /01-ErrorShow/ErrorShow.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: ErrorShow.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "Resource.h" 11 | 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | 16 | #define ESM_POKECODEANDLOOKUP (WM_USER + 100) 17 | const TCHAR g_szAppName[] = TEXT("Error Show"); 18 | 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | 22 | 23 | BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { 24 | 25 | chSETDLGICONS(hwnd, IDI_ERRORSHOW); 26 | 27 | // Don't accept error codes more than 5 digits long 28 | Edit_LimitText(GetDlgItem(hwnd, IDC_ERRORCODE), 5); 29 | 30 | // Look up the command-line passed error number 31 | SendMessage(hwnd, ESM_POKECODEANDLOOKUP, lParam, 0); 32 | return(TRUE); 33 | } 34 | 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | 38 | 39 | void Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) 40 | { 41 | 42 | switch (id) 43 | { 44 | 45 | case IDCANCEL: 46 | EndDialog(hwnd, id); 47 | break; 48 | 49 | case IDC_ALWAYSONTOP: 50 | SetWindowPos(hwnd, IsDlgButtonChecked(hwnd, IDC_ALWAYSONTOP) 51 | ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 52 | break; 53 | 54 | case IDC_ERRORCODE: 55 | EnableWindow(GetDlgItem(hwnd, IDOK), Edit_GetTextLength(hwndCtl) > 0); 56 | break; 57 | 58 | case IDOK: 59 | // Get the error code 60 | DWORD dwError = GetDlgItemInt(hwnd, IDC_ERRORCODE, NULL, FALSE); 61 | 62 | HLOCAL hlocal = NULL; // Buffer that gets the error message string 63 | 64 | // Use the default system locale since we look for Windows messages. 65 | // Note: this MAKELANGID combination has 0 as value 66 | DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); 67 | 68 | // Get the error code's textual description 69 | BOOL fOk = FormatMessage( 70 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | 71 | FORMAT_MESSAGE_ALLOCATE_BUFFER, 72 | NULL, dwError, systemLocale, 73 | (PTSTR) &hlocal, 0, NULL); 74 | 75 | if (!fOk) 76 | { 77 | // Is it a network-related error? 78 | HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, 79 | DONT_RESOLVE_DLL_REFERENCES); 80 | 81 | if (hDll != NULL) 82 | { 83 | fOk = FormatMessage( 84 | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS | 85 | FORMAT_MESSAGE_ALLOCATE_BUFFER, 86 | hDll, dwError, systemLocale, 87 | (PTSTR) &hlocal, 0, NULL); 88 | FreeLibrary(hDll); 89 | } 90 | } 91 | 92 | if (fOk && (hlocal != NULL)) 93 | { 94 | SetDlgItemText(hwnd, IDC_ERRORTEXT, (PCTSTR) LocalLock(hlocal)); 95 | LocalFree(hlocal); 96 | } 97 | else 98 | { 99 | SetDlgItemText(hwnd, IDC_ERRORTEXT, 100 | TEXT("No text found for this error number.")); 101 | } 102 | 103 | break; 104 | } 105 | } 106 | 107 | 108 | /////////////////////////////////////////////////////////////////////////////// 109 | 110 | 111 | INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 112 | { 113 | switch (uMsg) 114 | { 115 | chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog); 116 | chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand); 117 | 118 | case ESM_POKECODEANDLOOKUP: 119 | SetDlgItemInt(hwnd, IDC_ERRORCODE, (UINT) wParam, FALSE); 120 | FORWARD_WM_COMMAND(hwnd, IDOK, GetDlgItem(hwnd, IDOK), BN_CLICKED, 121 | PostMessage); 122 | SetForegroundWindow(hwnd); 123 | break; 124 | } 125 | 126 | return(FALSE); 127 | } 128 | 129 | 130 | /////////////////////////////////////////////////////////////////////////////// 131 | int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) 132 | { 133 | 134 | HWND hwnd = FindWindow(TEXT("#32770"), TEXT("Error Show")); 135 | 136 | if (IsWindow(hwnd)) 137 | { 138 | // An instance is already running, activate it and send it the new # 139 | SendMessage(hwnd, ESM_POKECODEANDLOOKUP, _ttoi(pszCmdLine), 0); 140 | } 141 | else 142 | { 143 | DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_ERRORSHOW), 144 | NULL, Dlg_Proc, _ttoi(pszCmdLine)); 145 | } 146 | 147 | return(0); 148 | } 149 | 150 | //////////////////////////////// End of File ////////////////////////////////// 151 | -------------------------------------------------------------------------------- /01-ErrorShow/ErrorShow.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/01-ErrorShow/ErrorShow.ico -------------------------------------------------------------------------------- /01-ErrorShow/ErrorShow.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_ERRORSHOW DIALOGEX 0, 0, 182, 42 30 | STYLE DS_SETFOREGROUND | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | 31 | WS_CAPTION | WS_SYSMENU 32 | CAPTION "Error Show" 33 | FONT 8, "MS Sans Serif" 34 | BEGIN 35 | LTEXT "Error:",IDC_STATIC,4,4,19,8 36 | EDITTEXT IDC_ERRORCODE,24,2,24,14,ES_AUTOHSCROLL | ES_NUMBER 37 | DEFPUSHBUTTON "Look up",IDOK,56,2,36,14 38 | CONTROL "&On top",IDC_ALWAYSONTOP,"Button",BS_AUTOCHECKBOX | 39 | WS_TABSTOP,104,4,38,10 40 | EDITTEXT IDC_ERRORTEXT,4,20,176,20,ES_MULTILINE | ES_AUTOVSCROLL | 41 | ES_READONLY | NOT WS_BORDER | WS_VSCROLL, 42 | WS_EX_CLIENTEDGE 43 | END 44 | 45 | 46 | ///////////////////////////////////////////////////////////////////////////// 47 | // 48 | // DESIGNINFO 49 | // 50 | 51 | #ifdef APSTUDIO_INVOKED 52 | GUIDELINES DESIGNINFO DISCARDABLE 53 | BEGIN 54 | IDD_ERRORSHOW, DIALOG 55 | BEGIN 56 | LEFTMARGIN, 7 57 | RIGHTMARGIN, 175 58 | TOPMARGIN, 7 59 | BOTTOMMARGIN, 35 60 | END 61 | END 62 | #endif // APSTUDIO_INVOKED 63 | 64 | 65 | #ifdef APSTUDIO_INVOKED 66 | ///////////////////////////////////////////////////////////////////////////// 67 | // 68 | // TEXTINCLUDE 69 | // 70 | 71 | 1 TEXTINCLUDE DISCARDABLE 72 | BEGIN 73 | "resource.h\0" 74 | END 75 | 76 | 2 TEXTINCLUDE DISCARDABLE 77 | BEGIN 78 | "#include ""Windows.h""\r\n" 79 | "\0" 80 | END 81 | 82 | 3 TEXTINCLUDE DISCARDABLE 83 | BEGIN 84 | "\r\n" 85 | "\0" 86 | END 87 | 88 | #endif // APSTUDIO_INVOKED 89 | 90 | 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Icon 94 | // 95 | 96 | // Icon with lowest ID value placed first to ensure application icon 97 | // remains consistent on all systems. 98 | IDI_ERRORSHOW ICON DISCARDABLE "ErrorShow.ico" 99 | #endif // English (U.S.) resources 100 | ///////////////////////////////////////////////////////////////////////////// 101 | 102 | 103 | 104 | #ifndef APSTUDIO_INVOKED 105 | ///////////////////////////////////////////////////////////////////////////// 106 | // 107 | // Generated from the TEXTINCLUDE 3 resource. 108 | // 109 | 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | #endif // not APSTUDIO_INVOKED 113 | 114 | -------------------------------------------------------------------------------- /01-ErrorShow/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by ErrorShow.rc 4 | // 5 | #define IDD_ERRORSHOW 101 6 | #define IDI_ERRORSHOW 102 7 | #define IDC_ERRORCODE 1000 8 | #define IDC_ERRORTEXT 1001 9 | #define IDC_ALWAYSONTOP 1002 10 | #define IDC_STATIC (-1) // all static controls 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 104 17 | #define _APS_NEXT_COMMAND_VALUE 40001 18 | #define _APS_NEXT_CONTROL_VALUE 1005 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /03-Singleton/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Singleton.rc 4 | // 5 | #define IDI_SINGLETON 102 6 | #define IDD_SINGLETON 129 7 | #define IDC_EDIT_DETAILS 1000 8 | #define IDC_STATIC -1 9 | 10 | // Next default values for new objects 11 | // 12 | #ifdef APSTUDIO_INVOKED 13 | #ifndef APSTUDIO_READONLY_SYMBOLS 14 | #define _APS_NO_MFC 1 15 | #define _APS_NEXT_RESOURCE_VALUE 130 16 | #define _APS_NEXT_COMMAND_VALUE 32771 17 | #define _APS_NEXT_CONTROL_VALUE 1001 18 | #define _APS_NEXT_SYMED_VALUE 110 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /03-Singleton/Singleton.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/03-Singleton/Singleton.ico -------------------------------------------------------------------------------- /03-Singleton/Singleton.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_SINGLETON ICON "Singleton.ico" 34 | 35 | #ifdef APSTUDIO_INVOKED 36 | ///////////////////////////////////////////////////////////////////////////// 37 | // 38 | // TEXTINCLUDE 39 | // 40 | 41 | 1 TEXTINCLUDE 42 | BEGIN 43 | "resource.h\0" 44 | END 45 | 46 | 2 TEXTINCLUDE 47 | BEGIN 48 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 49 | "#include ""windows.h""\r\n" 50 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 51 | "\0" 52 | END 53 | 54 | 3 TEXTINCLUDE 55 | BEGIN 56 | "\r\n" 57 | "\0" 58 | END 59 | 60 | #endif // APSTUDIO_INVOKED 61 | 62 | 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Dialog 66 | // 67 | 68 | IDD_SINGLETON DIALOGEX 0, 0, 195, 95 69 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 70 | EXSTYLE WS_EX_APPWINDOW 71 | CAPTION "Singleton" 72 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 73 | BEGIN 74 | DEFPUSHBUTTON "E&xit",IDOK,140,76,50,14 75 | EDITTEXT IDC_EDIT_DETAILS,4,5,186,67,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY 76 | END 77 | 78 | 79 | ///////////////////////////////////////////////////////////////////////////// 80 | // 81 | // DESIGNINFO 82 | // 83 | 84 | #ifdef APSTUDIO_INVOKED 85 | GUIDELINES DESIGNINFO 86 | BEGIN 87 | IDD_SINGLETON, DIALOG 88 | BEGIN 89 | LEFTMARGIN, 7 90 | RIGHTMARGIN, 188 91 | TOPMARGIN, 7 92 | BOTTOMMARGIN, 88 93 | END 94 | END 95 | #endif // APSTUDIO_INVOKED 96 | 97 | #endif // English (U.S.) resources 98 | ///////////////////////////////////////////////////////////////////////////// 99 | 100 | 101 | 102 | #ifndef APSTUDIO_INVOKED 103 | ///////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Generated from the TEXTINCLUDE 3 resource. 106 | // 107 | 108 | 109 | ///////////////////////////////////////////////////////////////////////////// 110 | #endif // not APSTUDIO_INVOKED 111 | 112 | -------------------------------------------------------------------------------- /04-ProcessInfo/ProcessInfo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/04-ProcessInfo/ProcessInfo.ico -------------------------------------------------------------------------------- /04-ProcessInfo/ProcessInfo.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_PROCESSINFO DIALOGEX 0, 0, 400, 317 30 | STYLE DS_SETFONT | DS_3DLOOK | DS_NOFAILCREATE | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 31 | EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE 32 | CAPTION "Process Information" 33 | MENU IDR_PROCESSINFO 34 | FONT 8, "MS Sans Serif", 0, 0, 0x1 35 | BEGIN 36 | PUSHBUTTON "System Processes",IDC_BTN_SYSTEM_PROCESSES,3,4,87,14 37 | COMBOBOX IDC_PROCESSMODULELIST,96,4,300,156,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP 38 | LISTBOX IDC_MODULEHELP,107,7,48,40,NOT LBS_NOTIFY | LBS_SORT | LBS_NOINTEGRALHEIGHT | NOT WS_VISIBLE | NOT WS_BORDER | WS_TABSTOP 39 | EDITTEXT IDC_RESULTS,4,24,392,284,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL 40 | END 41 | 42 | 43 | ///////////////////////////////////////////////////////////////////////////// 44 | // 45 | // DESIGNINFO 46 | // 47 | 48 | #ifdef APSTUDIO_INVOKED 49 | GUIDELINES DESIGNINFO 50 | BEGIN 51 | IDD_PROCESSINFO, DIALOG 52 | BEGIN 53 | LEFTMARGIN, 7 54 | RIGHTMARGIN, 393 55 | TOPMARGIN, 7 56 | BOTTOMMARGIN, 310 57 | END 58 | END 59 | #endif // APSTUDIO_INVOKED 60 | 61 | 62 | #ifdef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // TEXTINCLUDE 66 | // 67 | 68 | 1 TEXTINCLUDE 69 | BEGIN 70 | "resource.h\0" 71 | END 72 | 73 | 2 TEXTINCLUDE 74 | BEGIN 75 | "#include ""Windows.h""\r\n" 76 | "\0" 77 | END 78 | 79 | 3 TEXTINCLUDE 80 | BEGIN 81 | "\r\n" 82 | "\0" 83 | END 84 | 85 | #endif // APSTUDIO_INVOKED 86 | 87 | 88 | ///////////////////////////////////////////////////////////////////////////// 89 | // 90 | // Menu 91 | // 92 | 93 | IDR_PROCESSINFO MENU 94 | BEGIN 95 | MENUITEM "&Processes!", ID_PROCESSES 96 | MENUITEM "&Modules!", ID_MODULES 97 | MENUITEM "&VMMap!", ID_VMMAP 98 | END 99 | 100 | 101 | ///////////////////////////////////////////////////////////////////////////// 102 | // 103 | // Icon 104 | // 105 | 106 | // Icon with lowest ID value placed first to ensure application icon 107 | // remains consistent on all systems. 108 | IDI_PROCESSINFO ICON "ProcessInfo.ico" 109 | #endif // English (U.S.) resources 110 | ///////////////////////////////////////////////////////////////////////////// 111 | 112 | 113 | 114 | #ifndef APSTUDIO_INVOKED 115 | ///////////////////////////////////////////////////////////////////////////// 116 | // 117 | // Generated from the TEXTINCLUDE 3 resource. 118 | // 119 | 120 | 121 | ///////////////////////////////////////////////////////////////////////////// 122 | #endif // not APSTUDIO_INVOKED 123 | 124 | -------------------------------------------------------------------------------- /04-ProcessInfo/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by ProcessInfo.rc 4 | // 5 | #define IDD_PROCESSINFO 101 6 | #define IDR_PROCESSINFO 102 7 | #define IDI_PROCESSINFO 103 8 | #define IDC_PROCESSMODULELIST 1000 9 | #define IDC_RESULTS 1011 10 | #define IDC_MODULEHELP 1014 11 | #define IDC_BUTTON1 1016 12 | #define IDC_BTN_SYSTEM_PROCESSES 1016 13 | #define ID_PROCESSES 40001 14 | #define ID_MODULES 40002 15 | #define ID_VMMAP 40006 16 | 17 | // Next default values for new objects 18 | // 19 | #ifdef APSTUDIO_INVOKED 20 | #ifndef APSTUDIO_READONLY_SYMBOLS 21 | #define _APS_NEXT_RESOURCE_VALUE 104 22 | #define _APS_NEXT_COMMAND_VALUE 40007 23 | #define _APS_NEXT_CONTROL_VALUE 1017 24 | #define _APS_NEXT_SYMED_VALUE 101 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /05-JobLab/JobLab.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/05-JobLab/JobLab.ico -------------------------------------------------------------------------------- /05-JobLab/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by JobLab.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_JOBLAB 103 7 | #define IDI_JOBLAB 105 8 | #define IDB_BITMAP1 106 9 | #define IDB_BITMAP2 107 10 | #define IDC_PERPROCESSUSERTIMELIMIT 1000 11 | #define IDC_PERJOBUSERTIMELIMIT 1001 12 | #define IDC_MINWORKINGSETSIZE 1002 13 | #define IDC_MAXWORKINGSETSIZE 1004 14 | #define IDC_ACTIVEPROCESSLIMIT 1005 15 | #define IDC_PRIORITYCLASS 1006 16 | #define IDC_SCHEDULINGCLASS 1007 17 | #define IDC_RESTRICTACCESSTOOUTSIDEUSEROBJECTS 1008 18 | #define IDC_RESTRICTREADINGCLIPBOARD 1009 19 | #define IDC_RESTRICTWRITINGCLIPBOARD 1010 20 | #define IDC_RESTRICTEXITWINDOW 1011 21 | #define IDC_RESTRICTCHANGINGSYSTEMPARAMETERS 1012 22 | #define IDC_TERMINATE 1013 23 | #define IDC_STATUS 1014 24 | #define IDC_APPLYLIMITS 1015 25 | #define IDC_RESTRICTDESKTOPS 1016 26 | #define IDC_RESTRICTDISPLAYSETTINGS 1017 27 | #define IDC_RESTRICTGLOBALATOMS 1018 28 | #define IDC_CHILDPROCESSESCANBREAKAWAYFROMJOB 1019 29 | #define IDC_TERMINATEPROCESSONEXCEPTIONS 1020 30 | #define IDC_MAXCOMMITPERJOB 1021 31 | #define IDC_MAXCOMMITPERPROCESS 1022 32 | #define IDC_AFFINITYMASK 1023 33 | #define IDC_CHILDPROCESSESDOBREAKAWAYFROMJOB 1024 34 | #define IDC_PROCESSID 1025 35 | #define IDC_ASSIGNPROCESSTOJOB 1026 36 | #define IDC_PRESERVEJOBTIMEWHENAPPLYINGLIMITS 1027 37 | #define IDC_SPAWNCMDINJOB 1028 38 | 39 | // Next default values for new objects 40 | // 41 | #ifdef APSTUDIO_INVOKED 42 | #ifndef APSTUDIO_READONLY_SYMBOLS 43 | #define _APS_NEXT_RESOURCE_VALUE 108 44 | #define _APS_NEXT_COMMAND_VALUE 40001 45 | #define _APS_NEXT_CONTROL_VALUE 1029 46 | #define _APS_NEXT_SYMED_VALUE 101 47 | #endif 48 | #endif 49 | -------------------------------------------------------------------------------- /07-SchedLab/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by SchedLab.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_SCHEDLAB 101 7 | #define IDI_SCHEDLAB 103 8 | #define IDC_PROCESSPRIORITYCLASS 1015 9 | #define IDC_THREADRELATIVEPRIORITY 1016 10 | #define IDC_SLEEPTIME 1017 11 | #define IDC_SUSPEND 1018 12 | #define IDC_WORK 1020 13 | 14 | // Next default values for new objects 15 | // 16 | #ifdef APSTUDIO_INVOKED 17 | #ifndef APSTUDIO_READONLY_SYMBOLS 18 | #define _APS_NEXT_RESOURCE_VALUE 104 19 | #define _APS_NEXT_COMMAND_VALUE 40007 20 | #define _APS_NEXT_CONTROL_VALUE 1022 21 | #define _APS_NEXT_SYMED_VALUE 101 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /07-SchedLab/SchedLab.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/07-SchedLab/SchedLab.ico -------------------------------------------------------------------------------- /07-SchedLab/SchedLab.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_SCHEDLAB DIALOGEX 0, 0, 209, 70 30 | STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | 31 | WS_SYSMENU 32 | EXSTYLE WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE 33 | CAPTION "Scheduling Lab" 34 | FONT 8, "MS Sans Serif" 35 | BEGIN 36 | LTEXT "&Process priority class:",IDC_STATIC,4,6,68,8 37 | COMBOBOX IDC_PROCESSPRIORITYCLASS,84,4,72,80,CBS_DROPDOWNLIST | 38 | WS_TABSTOP 39 | LTEXT "&Thread relative priority:",IDC_STATIC,4,20,72,8 40 | COMBOBOX IDC_THREADRELATIVEPRIORITY,84,18,72,76,CBS_DROPDOWNLIST | 41 | WS_TABSTOP 42 | LTEXT "Sleep (0 to 9999 &ms):",IDC_STATIC,4,36,68,8 43 | EDITTEXT IDC_SLEEPTIME,84,34,32,14,ES_NUMBER 44 | PUSHBUTTON "&Suspend",IDC_SUSPEND,4,52,49,14 45 | LISTBOX IDC_WORK,160,4,48,60,NOT LBS_NOTIFY | 46 | LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_TABSTOP 47 | END 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // DESIGNINFO 53 | // 54 | 55 | #ifdef APSTUDIO_INVOKED 56 | GUIDELINES DESIGNINFO DISCARDABLE 57 | BEGIN 58 | IDD_SCHEDLAB, DIALOG 59 | BEGIN 60 | LEFTMARGIN, 7 61 | RIGHTMARGIN, 202 62 | TOPMARGIN, 7 63 | BOTTOMMARGIN, 63 64 | END 65 | END 66 | #endif // APSTUDIO_INVOKED 67 | 68 | 69 | #ifdef APSTUDIO_INVOKED 70 | ///////////////////////////////////////////////////////////////////////////// 71 | // 72 | // TEXTINCLUDE 73 | // 74 | 75 | 1 TEXTINCLUDE DISCARDABLE 76 | BEGIN 77 | "resource.h\0" 78 | END 79 | 80 | 2 TEXTINCLUDE DISCARDABLE 81 | BEGIN 82 | "#include ""Windows.h""\r\n" 83 | "\0" 84 | END 85 | 86 | 3 TEXTINCLUDE DISCARDABLE 87 | BEGIN 88 | "\r\n" 89 | "\0" 90 | END 91 | 92 | #endif // APSTUDIO_INVOKED 93 | 94 | 95 | ///////////////////////////////////////////////////////////////////////////// 96 | // 97 | // Icon 98 | // 99 | 100 | // Icon with lowest ID value placed first to ensure application icon 101 | // remains consistent on all systems. 102 | IDI_SCHEDLAB ICON DISCARDABLE "SchedLab.ico" 103 | #endif // English (U.S.) resources 104 | ///////////////////////////////////////////////////////////////////////////// 105 | 106 | 107 | 108 | #ifndef APSTUDIO_INVOKED 109 | ///////////////////////////////////////////////////////////////////////////// 110 | // 111 | // Generated from the TEXTINCLUDE 3 resource. 112 | // 113 | 114 | 115 | ///////////////////////////////////////////////////////////////////////////// 116 | #endif // not APSTUDIO_INVOKED 117 | 118 | -------------------------------------------------------------------------------- /08-Queue/Queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /08-Queue/Queue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/08-Queue/Queue.ico -------------------------------------------------------------------------------- /08-Queue/Queue.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_QUEUE DIALOGEX 38, 36, 318, 249 30 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 31 | CAPTION "Queue" 32 | FONT 8, "MS Sans Serif", 0, 0, 0x0 33 | BEGIN 34 | GROUPBOX "&Client threads",IDC_STATIC,4,4,150,216 35 | LISTBOX IDC_CLIENTS,8,16,142,200,NOT LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP 36 | GROUPBOX "&Server threads",IDC_STATIC,160,4,154,216 37 | LISTBOX IDC_SERVERS,164,16,146,200,NOT LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP 38 | DEFPUSHBUTTON "&Stop",IDC_BTN_STOP,260,229,50,14 39 | END 40 | 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | // 44 | // Icon 45 | // 46 | 47 | // Icon with lowest ID value placed first to ensure application icon 48 | // remains consistent on all systems. 49 | IDI_QUEUE ICON "Queue.ico" 50 | 51 | #ifdef APSTUDIO_INVOKED 52 | ///////////////////////////////////////////////////////////////////////////// 53 | // 54 | // TEXTINCLUDE 55 | // 56 | 57 | 1 TEXTINCLUDE 58 | BEGIN 59 | "Resource.h\0" 60 | END 61 | 62 | 2 TEXTINCLUDE 63 | BEGIN 64 | "#include ""Windows.h""\r\n" 65 | "\0" 66 | END 67 | 68 | 3 TEXTINCLUDE 69 | BEGIN 70 | "\r\n" 71 | "\0" 72 | END 73 | 74 | #endif // APSTUDIO_INVOKED 75 | 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // DESIGNINFO 80 | // 81 | 82 | #ifdef APSTUDIO_INVOKED 83 | GUIDELINES DESIGNINFO 84 | BEGIN 85 | IDD_QUEUE, DIALOG 86 | BEGIN 87 | RIGHTMARGIN, 264 88 | BOTTOMMARGIN, 154 89 | END 90 | END 91 | #endif // APSTUDIO_INVOKED 92 | 93 | #endif // English (U.S.) resources 94 | ///////////////////////////////////////////////////////////////////////////// 95 | 96 | 97 | 98 | #ifndef APSTUDIO_INVOKED 99 | ///////////////////////////////////////////////////////////////////////////// 100 | // 101 | // Generated from the TEXTINCLUDE 3 resource. 102 | // 103 | 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | #endif // not APSTUDIO_INVOKED 107 | 108 | -------------------------------------------------------------------------------- /08-Queue/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Queue.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_QUEUE 1 7 | #define IDI_QUEUE 102 8 | #define IDC_CLIENTS 1000 9 | #define IDC_SERVERS 1001 10 | #define IDC_BTN_STOP 1002 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 105 17 | #define _APS_NEXT_COMMAND_VALUE 40001 18 | #define _APS_NEXT_CONTROL_VALUE 1003 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /08-UserSyncCompare/UserSyncCompare.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: UserSyncCompare.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | // Stop watch class from Chapter 7 13 | class CStopwatch { 14 | public: 15 | CStopwatch() { QueryPerformanceFrequency(&m_liPerfFreq); Start(); } 16 | 17 | void Start() { QueryPerformanceCounter(&m_liPerfStart); } 18 | 19 | // Returns # of milliseconds since Start was called 20 | __int64 Now() const { 21 | LARGE_INTEGER liPerfNow; 22 | QueryPerformanceCounter(&liPerfNow); 23 | return(((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000) 24 | / m_liPerfFreq.QuadPart); 25 | } 26 | 27 | private: 28 | LARGE_INTEGER m_liPerfFreq; // Counts per second 29 | LARGE_INTEGER m_liPerfStart; // Starting count 30 | }; 31 | 32 | 33 | DWORD g_nIterations = 1000000; 34 | typedef void (CALLBACK* OPERATIONFUNC)(); 35 | 36 | DWORD WINAPI ThreadIterationFunction(PVOID operationFunc) { 37 | OPERATIONFUNC op = (OPERATIONFUNC) operationFunc; 38 | for (DWORD iteration = 0; iteration < g_nIterations; iteration++) { 39 | op(); 40 | } 41 | return 0; 42 | } 43 | 44 | void MeasureConcurrentOperation( 45 | TCHAR* operationName, DWORD nThreads, OPERATIONFUNC operationFunc) { 46 | HANDLE* phThreads = new HANDLE[nThreads]; 47 | 48 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); 49 | for (DWORD currentThread = 0; currentThread < nThreads; currentThread++) { 50 | phThreads[currentThread] = 51 | CreateThread(NULL, 0, ThreadIterationFunction, operationFunc, 0, NULL); 52 | } 53 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); 54 | 55 | CStopwatch watch; 56 | WaitForMultipleObjects(nThreads, phThreads, TRUE, INFINITE); 57 | __int64 elapsedTime = watch.Now(); 58 | _tprintf( 59 | TEXT("Threads=%u, Milliseconds=%u, Test=%s\n"), 60 | nThreads, (DWORD)elapsedTime, operationName); 61 | 62 | // Don't forget to clean up the thread handles 63 | for (DWORD currentThread = 0; currentThread < nThreads; currentThread++) { 64 | CloseHandle(phThreads[currentThread]); 65 | } 66 | delete phThreads; 67 | } 68 | 69 | 70 | 71 | // ----------------------------------------------------------- 72 | // List of tests to run: 73 | // ----------------------------------------------------------- 74 | // Reading from a volatile int with NO synchronization at all 75 | // Writing to an int using InterlockedIncrement 76 | // Reading from a volatile int using critical sections 77 | // Read from a volatile int using SRWLock 78 | // Read from a volatile int using Mutex 79 | // ----------------------------------------------------------- 80 | 81 | volatile LONG gv_value = 0; 82 | 83 | // 'lValue': local variable is initialized but not referenced 84 | #pragma warning(disable:4189) 85 | void WINAPI VolatileReadCallback() 86 | { 87 | LONG lValue = gv_value; 88 | } 89 | #pragma warning(default:4189) 90 | 91 | void WINAPI VolatileWriteCallback() 92 | { 93 | gv_value = 0; 94 | } 95 | 96 | void WINAPI InterlockedIncrementCallback() 97 | { 98 | InterlockedIncrement(&gv_value); 99 | } 100 | 101 | CRITICAL_SECTION g_cs; 102 | void WINAPI CriticalSectionCallback() 103 | { 104 | EnterCriticalSection(&g_cs); 105 | gv_value = 0; 106 | LeaveCriticalSection(&g_cs); 107 | } 108 | 109 | 110 | HANDLE g_hMutex; 111 | void WINAPI MutexCallback() 112 | { 113 | WaitForSingleObject(g_hMutex, INFINITE); 114 | gv_value = 0; 115 | ReleaseMutex(g_hMutex); 116 | } 117 | 118 | 119 | // Slim Reader/Writer Lock global variable 120 | SRWLOCK g_srwLock; 121 | 122 | void WINAPI SRWLockReadCallback() { 123 | AcquireSRWLockShared(&g_srwLock); 124 | gv_value = 0; 125 | ReleaseSRWLockShared(&g_srwLock); 126 | } 127 | 128 | void WINAPI SRWLockWriteCallback() { 129 | AcquireSRWLockExclusive(&g_srwLock); 130 | gv_value = 0; 131 | ReleaseSRWLockExclusive(&g_srwLock); 132 | } 133 | 134 | 135 | int _tmain(int argc, _TCHAR* argv[]) { 136 | 137 | for (int nThreads = 1; nThreads <= 4; nThreads *= 2) { 138 | MeasureConcurrentOperation(TEXT("Volatile Read"), nThreads, VolatileReadCallback); 139 | MeasureConcurrentOperation(TEXT("Volatile Write"), nThreads, VolatileWriteCallback); 140 | MeasureConcurrentOperation(TEXT("Interlocked Increment"), nThreads, InterlockedIncrementCallback); 141 | 142 | // Prepare the critical section 143 | InitializeCriticalSection(&g_cs); 144 | MeasureConcurrentOperation(TEXT("Critical Section"), nThreads, CriticalSectionCallback); 145 | // Don't forget to cleanup 146 | DeleteCriticalSection(&g_cs); 147 | 148 | // Prepare the Slim Reader/Writer lock 149 | InitializeSRWLock(&g_srwLock); 150 | MeasureConcurrentOperation(TEXT("SRWLock Read"), nThreads, SRWLockReadCallback); 151 | MeasureConcurrentOperation(TEXT("SRWLock Write"), nThreads, SRWLockWriteCallback); 152 | // NOTE: You can't cleanup a Slim Reader/Writer lock 153 | 154 | // Prepare the mutex 155 | g_hMutex = CreateMutex(NULL, false, NULL); 156 | MeasureConcurrentOperation(TEXT("Mutex"), nThreads, MutexCallback); 157 | CloseHandle(g_hMutex); 158 | _tprintf(TEXT("\n")); 159 | } 160 | 161 | return(0); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /09-Handshake/Handshake.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/09-Handshake/Handshake.ico -------------------------------------------------------------------------------- /09-Handshake/Handshake.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_HANDSHAKE DIALOG DISCARDABLE 0, 0, 256, 81 30 | STYLE DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU 31 | CAPTION "Handshake" 32 | FONT 8, "MS Sans Serif" 33 | BEGIN 34 | GROUPBOX "Client side",IDC_STATIC,4,4,248,72 35 | LTEXT "&Request:",IDC_STATIC,12,18,30,8 36 | EDITTEXT IDC_REQUEST,48,16,196,14,ES_AUTOHSCROLL 37 | DEFPUSHBUTTON "&Submit Request to Server",IDC_SUBMIT,80,36,96,14 38 | LTEXT "Result:",IDC_STATIC,12,58,23,8 39 | EDITTEXT IDC_RESULT,48,56,196,16,ES_AUTOHSCROLL | ES_READONLY 40 | END 41 | 42 | 43 | ///////////////////////////////////////////////////////////////////////////// 44 | // 45 | // DESIGNINFO 46 | // 47 | 48 | #ifdef APSTUDIO_INVOKED 49 | GUIDELINES DESIGNINFO DISCARDABLE 50 | BEGIN 51 | IDD_HANDSHAKE, DIALOG 52 | BEGIN 53 | LEFTMARGIN, 7 54 | RIGHTMARGIN, 249 55 | TOPMARGIN, 7 56 | BOTTOMMARGIN, 74 57 | END 58 | END 59 | #endif // APSTUDIO_INVOKED 60 | 61 | 62 | #ifdef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // TEXTINCLUDE 66 | // 67 | 68 | 1 TEXTINCLUDE DISCARDABLE 69 | BEGIN 70 | "resource.h\0" 71 | END 72 | 73 | 2 TEXTINCLUDE DISCARDABLE 74 | BEGIN 75 | "#include ""Windows.h""\r\n" 76 | "\0" 77 | END 78 | 79 | 3 TEXTINCLUDE DISCARDABLE 80 | BEGIN 81 | "\r\n" 82 | "\0" 83 | END 84 | 85 | #endif // APSTUDIO_INVOKED 86 | 87 | 88 | ///////////////////////////////////////////////////////////////////////////// 89 | // 90 | // Icon 91 | // 92 | 93 | // Icon with lowest ID value placed first to ensure application icon 94 | // remains consistent on all systems. 95 | IDI_HANDSHAKE ICON DISCARDABLE "Handshake.ico" 96 | #endif // English (U.S.) resources 97 | ///////////////////////////////////////////////////////////////////////////// 98 | 99 | 100 | 101 | #ifndef APSTUDIO_INVOKED 102 | ///////////////////////////////////////////////////////////////////////////// 103 | // 104 | // Generated from the TEXTINCLUDE 3 resource. 105 | // 106 | 107 | 108 | ///////////////////////////////////////////////////////////////////////////// 109 | #endif // not APSTUDIO_INVOKED 110 | 111 | -------------------------------------------------------------------------------- /09-Handshake/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Handshake.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_HANDSHAKE 101 7 | #define IDI_HANDSHAKE 102 8 | #define IDC_REQUEST 1000 9 | #define IDC_RESULT 1001 10 | #define IDC_SUBMIT 1002 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 103 17 | #define _APS_NEXT_COMMAND_VALUE 40001 18 | #define _APS_NEXT_CONTROL_VALUE 1004 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /09-LockCop/LockCop.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/09-LockCop/LockCop.ico -------------------------------------------------------------------------------- /09-LockCop/LockCop.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_LOCKCOP ICON "LockCop.ico" 34 | 35 | #ifdef APSTUDIO_INVOKED 36 | ///////////////////////////////////////////////////////////////////////////// 37 | // 38 | // TEXTINCLUDE 39 | // 40 | 41 | 1 TEXTINCLUDE 42 | BEGIN 43 | "resource.h\0" 44 | END 45 | 46 | 2 TEXTINCLUDE 47 | BEGIN 48 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 49 | "#include ""windows.h""\r\n" 50 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 51 | "\0" 52 | END 53 | 54 | 3 TEXTINCLUDE 55 | BEGIN 56 | "\r\n" 57 | "\0" 58 | END 59 | 60 | #endif // APSTUDIO_INVOKED 61 | 62 | 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Dialog 66 | // 67 | 68 | IDD_LOCKCOP DIALOGEX 0, 0, 329, 253 69 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 70 | EXSTYLE WS_EX_APPWINDOW 71 | CAPTION "LockCop" 72 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 73 | BEGIN 74 | LTEXT "&Processes:",IDC_STATIC,90,7,36,8 75 | COMBOBOX IDC_COMBO_PROCESS,129,5,139,158,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP 76 | PUSHBUTTON "&Refresh",IDC_BTN_REFRESH,274,4,50,14 77 | GROUPBOX "&Lock Details",IDC_STATIC,5,39,318,191 78 | EDITTEXT IDC_EDIT_DETAILS,12,56,303,166,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL 79 | DEFPUSHBUTTON "&Update",IDC_BTN_UPDATE,55,36,50,14 80 | PUSHBUTTON "E&xit",IDOK,274,235,50,14 81 | ICON IDI_LOCKCOP,IDC_STATIC,16,9,20,20,SS_CENTERIMAGE | SS_REALSIZEIMAGE 82 | END 83 | 84 | 85 | ///////////////////////////////////////////////////////////////////////////// 86 | // 87 | // DESIGNINFO 88 | // 89 | 90 | #ifdef APSTUDIO_INVOKED 91 | GUIDELINES DESIGNINFO 92 | BEGIN 93 | IDD_LOCKCOP, DIALOG 94 | BEGIN 95 | LEFTMARGIN, 7 96 | RIGHTMARGIN, 322 97 | TOPMARGIN, 7 98 | BOTTOMMARGIN, 246 99 | END 100 | END 101 | #endif // APSTUDIO_INVOKED 102 | 103 | #endif // English (U.S.) resources 104 | ///////////////////////////////////////////////////////////////////////////// 105 | 106 | 107 | 108 | #ifndef APSTUDIO_INVOKED 109 | ///////////////////////////////////////////////////////////////////////////// 110 | // 111 | // Generated from the TEXTINCLUDE 3 resource. 112 | // 113 | 114 | 115 | ///////////////////////////////////////////////////////////////////////////// 116 | #endif // not APSTUDIO_INVOKED 117 | 118 | -------------------------------------------------------------------------------- /09-LockCop/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by LockCop.rc 4 | // 5 | #define IDI_LOCKCOP 107 6 | #define IDD_LOCKCOP 130 7 | #define IDC_COMBO_PROCESS 1000 8 | #define IDC_BTN_REFRESH 1001 9 | #define IDC_EDIT_DETAILS 1002 10 | #define IDC_BTN_UPDATE 1003 11 | #define IDC_STATIC -1 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NO_MFC 1 18 | #define _APS_NEXT_RESOURCE_VALUE 131 19 | #define _APS_NEXT_COMMAND_VALUE 32771 20 | #define _APS_NEXT_CONTROL_VALUE 1004 21 | #define _APS_NEXT_SYMED_VALUE 110 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /09-Queue/Queue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/09-Queue/Queue.ico -------------------------------------------------------------------------------- /09-Queue/Queue.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_QUEUE DIALOG DISCARDABLE 38, 36, 298, 225 30 | STYLE WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 31 | CAPTION "Queue" 32 | FONT 8, "MS Sans Serif" 33 | BEGIN 34 | GROUPBOX "&Client threads",IDC_STATIC,4,4,140,216 35 | LISTBOX IDC_CLIENTS,8,16,132,200,NOT LBS_NOTIFY | 36 | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP 37 | GROUPBOX "&Server threads",IDC_STATIC,156,4,140,216 38 | LISTBOX IDC_SERVERS,160,16,132,200,NOT LBS_NOTIFY | 39 | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP 40 | END 41 | 42 | 43 | ///////////////////////////////////////////////////////////////////////////// 44 | // 45 | // Icon 46 | // 47 | 48 | // Icon with lowest ID value placed first to ensure application icon 49 | // remains consistent on all systems. 50 | IDI_QUEUE ICON DISCARDABLE "Queue.Ico" 51 | 52 | #ifdef APSTUDIO_INVOKED 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // 55 | // TEXTINCLUDE 56 | // 57 | 58 | 1 TEXTINCLUDE DISCARDABLE 59 | BEGIN 60 | "Resource.h\0" 61 | END 62 | 63 | 2 TEXTINCLUDE DISCARDABLE 64 | BEGIN 65 | "#include ""Windows.h""\r\n" 66 | "\0" 67 | END 68 | 69 | 3 TEXTINCLUDE DISCARDABLE 70 | BEGIN 71 | "\r\n" 72 | "\0" 73 | END 74 | 75 | #endif // APSTUDIO_INVOKED 76 | 77 | 78 | ///////////////////////////////////////////////////////////////////////////// 79 | // 80 | // DESIGNINFO 81 | // 82 | 83 | #ifdef APSTUDIO_INVOKED 84 | GUIDELINES DESIGNINFO DISCARDABLE 85 | BEGIN 86 | IDD_QUEUE, DIALOG 87 | BEGIN 88 | RIGHTMARGIN, 244 89 | BOTTOMMARGIN, 130 90 | END 91 | END 92 | #endif // APSTUDIO_INVOKED 93 | 94 | #endif // English (U.S.) resources 95 | ///////////////////////////////////////////////////////////////////////////// 96 | 97 | 98 | 99 | #ifndef APSTUDIO_INVOKED 100 | ///////////////////////////////////////////////////////////////////////////// 101 | // 102 | // Generated from the TEXTINCLUDE 3 resource. 103 | // 104 | 105 | 106 | ///////////////////////////////////////////////////////////////////////////// 107 | #endif // not APSTUDIO_INVOKED 108 | 109 | -------------------------------------------------------------------------------- /09-Queue/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Queue.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_QUEUE 1 7 | #define IDI_QUEUE 102 8 | #define IDC_CLIENTS 1000 9 | #define IDC_SERVERS 1001 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 105 16 | #define _APS_NEXT_COMMAND_VALUE 40001 17 | #define _APS_NEXT_CONTROL_VALUE 1001 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /10-FileCopy/FileCopy.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/10-FileCopy/FileCopy.ico -------------------------------------------------------------------------------- /10-FileCopy/FileCopy.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_FILECOPY ICON DISCARDABLE "FileCopy.ico" 32 | 33 | ///////////////////////////////////////////////////////////////////////////// 34 | // 35 | // Dialog 36 | // 37 | 38 | IDD_FILECOPY DIALOG DISCARDABLE 15, 24, 220, 34 39 | STYLE DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 40 | CAPTION "FileCopy" 41 | FONT 8, "MS Sans Serif" 42 | BEGIN 43 | DEFPUSHBUTTON "&Pathname...",IDC_PATHNAME,4,4,43,12,WS_GROUP 44 | EDITTEXT IDC_SRCFILE,52,4,164,12,ES_AUTOHSCROLL | ES_READONLY 45 | DEFPUSHBUTTON "&Copy",IDOK,4,20,43,12 46 | LTEXT "File size:",-1,128,22,28,8 47 | LTEXT "0",IDC_SRCFILESIZE,162,20,54,12,SS_SUNKEN 48 | END 49 | 50 | 51 | #ifdef APSTUDIO_INVOKED 52 | ///////////////////////////////////////////////////////////////////////////// 53 | // 54 | // TEXTINCLUDE 55 | // 56 | 57 | 1 TEXTINCLUDE DISCARDABLE 58 | BEGIN 59 | "Resource.h\0" 60 | END 61 | 62 | 2 TEXTINCLUDE DISCARDABLE 63 | BEGIN 64 | "#include ""Windows.h""\r\n" 65 | "\0" 66 | END 67 | 68 | 3 TEXTINCLUDE DISCARDABLE 69 | BEGIN 70 | "\r\n" 71 | "\0" 72 | END 73 | 74 | #endif // APSTUDIO_INVOKED 75 | 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // DESIGNINFO 80 | // 81 | 82 | #ifdef APSTUDIO_INVOKED 83 | GUIDELINES DESIGNINFO DISCARDABLE 84 | BEGIN 85 | IDD_FILECOPY, DIALOG 86 | BEGIN 87 | RIGHTMARGIN, 216 88 | BOTTOMMARGIN, 30 89 | END 90 | END 91 | #endif // APSTUDIO_INVOKED 92 | 93 | #endif // English (U.S.) resources 94 | ///////////////////////////////////////////////////////////////////////////// 95 | 96 | 97 | 98 | #ifndef APSTUDIO_INVOKED 99 | ///////////////////////////////////////////////////////////////////////////// 100 | // 101 | // Generated from the TEXTINCLUDE 3 resource. 102 | // 103 | 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | #endif // not APSTUDIO_INVOKED 107 | 108 | -------------------------------------------------------------------------------- /10-FileCopy/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by FileCopy.rc 4 | // 5 | #define IDC_PATHNAME 100 6 | #define IDC_SRCFILE 101 7 | #define IDC_SRCFILESIZE 102 8 | #define IDI_FILECOPY 103 9 | #define IDD_FILECOPY 104 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 105 16 | #define _APS_NEXT_COMMAND_VALUE 40001 17 | #define _APS_NEXT_CONTROL_VALUE 1000 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /11-Batch/Batch.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: Batch.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | // C RunTime Header Files 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "Batch.h" 21 | 22 | 23 | ////////////////////////////////////////////////////////////////////////////// 24 | 25 | 26 | // Global variables 27 | HWND g_hDlg = NULL; 28 | PTP_WORK g_pWorkItem = NULL; 29 | volatile LONG g_nCurrentTask = 0; 30 | 31 | 32 | // Global definitions 33 | #define WM_APP_COMPLETED (WM_APP+123) 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | 38 | 39 | void AddMessage(LPCTSTR szMsg) { 40 | 41 | HWND hListBox = GetDlgItem(g_hDlg, IDC_LB_STATUS); 42 | ListBox_SetCurSel(hListBox, ListBox_AddString(hListBox, szMsg)); 43 | } 44 | 45 | 46 | ////////////////////////////////////////////////////////////////////////////// 47 | 48 | 49 | void NTAPI TaskHandler(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work) { 50 | 51 | LONG currentTask = InterlockedIncrement(&g_nCurrentTask); 52 | 53 | TCHAR szMsg[MAX_PATH]; 54 | StringCchPrintf( 55 | szMsg, _countof(szMsg), 56 | TEXT("[%u] Task #%u is starting."), GetCurrentThreadId(), currentTask); 57 | AddMessage(szMsg); 58 | 59 | // Simulate a lot of work 60 | Sleep(currentTask * 1000); 61 | 62 | StringCchPrintf( 63 | szMsg, _countof(szMsg), 64 | TEXT("[%u] Task #%u is done."), GetCurrentThreadId(), currentTask); 65 | AddMessage(szMsg); 66 | 67 | if (InterlockedDecrement(&g_nCurrentTask) == 0) 68 | { 69 | // Notify the UI thread for completion. 70 | PostMessage(g_hDlg, WM_APP_COMPLETED, 0, (LPARAM)currentTask); 71 | } 72 | } 73 | 74 | 75 | ////////////////////////////////////////////////////////////////////////////// 76 | 77 | 78 | void OnStartBatch() { 79 | 80 | // Disable Start button 81 | Button_Enable(GetDlgItem(g_hDlg, IDC_BTN_START_BATCH), FALSE); 82 | 83 | AddMessage(TEXT("----Start a new batch----")); 84 | 85 | // Submit 4 tasks by using the same work item 86 | SubmitThreadpoolWork(g_pWorkItem); 87 | SubmitThreadpoolWork(g_pWorkItem); 88 | SubmitThreadpoolWork(g_pWorkItem); 89 | SubmitThreadpoolWork(g_pWorkItem); 90 | 91 | AddMessage(TEXT("4 tasks are submitted.")); 92 | } 93 | 94 | 95 | ////////////////////////////////////////////////////////////////////////////// 96 | 97 | 98 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 99 | 100 | switch (id) { 101 | case IDOK: 102 | case IDCANCEL: 103 | EndDialog(hWnd, id); 104 | break; 105 | 106 | case IDC_BTN_START_BATCH: 107 | OnStartBatch(); 108 | break; 109 | } 110 | } 111 | 112 | 113 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 114 | 115 | // Keep track of main dialog window for error messages 116 | g_hDlg = hWnd; 117 | 118 | return(TRUE); 119 | } 120 | 121 | 122 | ////////////////////////////////////////////////////////////////////////////// 123 | 124 | 125 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 126 | 127 | switch (uMsg) { 128 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 129 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 130 | case WM_APP_COMPLETED: { 131 | TCHAR szMsg[MAX_PATH+1]; 132 | StringCchPrintf( 133 | szMsg, _countof(szMsg), 134 | TEXT("____Task #%u was the last task of the batch____"), lParam); 135 | AddMessage(szMsg); 136 | 137 | // Don't forget to enable the button 138 | Button_Enable(GetDlgItem(hWnd, IDC_BTN_START_BATCH), TRUE); 139 | } 140 | break; 141 | } 142 | 143 | return(FALSE); 144 | } 145 | 146 | 147 | 148 | int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR pCmdLine, int) { 149 | 150 | // Create the work item that will be used by all tasks 151 | g_pWorkItem = CreateThreadpoolWork(TaskHandler, NULL, NULL); 152 | if (g_pWorkItem == NULL) { 153 | MessageBox(NULL, TEXT("Impossible to create the work item for tasks."), 154 | TEXT(""), MB_ICONSTOP); 155 | return(-1); 156 | } 157 | 158 | DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, Dlg_Proc, 159 | _ttoi(pCmdLine)); 160 | 161 | // Don't forget to delete the work item 162 | CloseThreadpoolWork(g_pWorkItem); 163 | 164 | return(0); 165 | } 166 | 167 | 168 | //////////////////////////////// End of File ///////////////////////////////// -------------------------------------------------------------------------------- /11-Batch/Batch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /11-Batch/Batch.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/11-Batch/Batch.ico -------------------------------------------------------------------------------- /11-Batch/Batch.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_MY10BATCH ICON "Batch.ico" 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | // 37 | // Dialog 38 | // 39 | 40 | IDD_MAIN DIALOGEX 0, 0, 229, 151 41 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU 42 | CAPTION "Batch processing with thread pool" 43 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 44 | BEGIN 45 | DEFPUSHBUTTON "&Exit",IDOK,172,130,50,14 46 | LISTBOX IDC_LB_STATUS,7,27,215,96,LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,WS_EX_STATICEDGE 47 | PUSHBUTTON "Start batch",IDC_BTN_START_BATCH,7,7,59,14 48 | END 49 | 50 | 51 | #ifdef APSTUDIO_INVOKED 52 | ///////////////////////////////////////////////////////////////////////////// 53 | // 54 | // TEXTINCLUDE 55 | // 56 | 57 | 1 TEXTINCLUDE 58 | BEGIN 59 | "resource.h\0" 60 | END 61 | 62 | 2 TEXTINCLUDE 63 | BEGIN 64 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 65 | "#include ""windows.h""\r\n" 66 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 67 | "\0" 68 | END 69 | 70 | 3 TEXTINCLUDE 71 | BEGIN 72 | "\r\n" 73 | "\0" 74 | END 75 | 76 | #endif // APSTUDIO_INVOKED 77 | 78 | 79 | ///////////////////////////////////////////////////////////////////////////// 80 | // 81 | // DESIGNINFO 82 | // 83 | 84 | #ifdef APSTUDIO_INVOKED 85 | GUIDELINES DESIGNINFO 86 | BEGIN 87 | IDD_MAIN, DIALOG 88 | BEGIN 89 | LEFTMARGIN, 7 90 | RIGHTMARGIN, 222 91 | TOPMARGIN, 7 92 | BOTTOMMARGIN, 144 93 | END 94 | END 95 | #endif // APSTUDIO_INVOKED 96 | 97 | #endif // English (U.S.) resources 98 | ///////////////////////////////////////////////////////////////////////////// 99 | 100 | 101 | 102 | #ifndef APSTUDIO_INVOKED 103 | ///////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Generated from the TEXTINCLUDE 3 resource. 106 | // 107 | 108 | 109 | ///////////////////////////////////////////////////////////////////////////// 110 | #endif // not APSTUDIO_INVOKED 111 | 112 | -------------------------------------------------------------------------------- /11-Batch/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Batch.rc 4 | // 5 | #define IDD_MY10BATCH_DIALOG 102 6 | #define IDI_MY10BATCH 107 7 | #define IDI_SMALL 108 8 | #define IDR_MAINFRAME 128 9 | #define IDD_MAIN 129 10 | #define IDC_BTN_START_BATCH 1000 11 | #define IDC_LB_STATUS 1001 12 | #define IDC_STATIC -1 13 | 14 | // Next default values for new objects 15 | // 16 | #ifdef APSTUDIO_INVOKED 17 | #ifndef APSTUDIO_READONLY_SYMBOLS 18 | #define _APS_NO_MFC 1 19 | #define _APS_NEXT_RESOURCE_VALUE 130 20 | #define _APS_NEXT_COMMAND_VALUE 32771 21 | #define _APS_NEXT_CONTROL_VALUE 1002 22 | #define _APS_NEXT_SYMED_VALUE 110 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /11-PrivateBatch/PrivateBatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /11-PrivateBatch/PrivateBatch.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/11-PrivateBatch/PrivateBatch.ico -------------------------------------------------------------------------------- /11-PrivateBatch/PrivateBatch.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_MYPRIVATEBATCH ICON "PrivateBatch.ico" 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | // 37 | // Menu 38 | // 39 | 40 | IDC_MYPRIVATEBATCH MENU 41 | BEGIN 42 | POPUP "&File" 43 | BEGIN 44 | MENUITEM "E&xit", IDM_EXIT 45 | END 46 | POPUP "&Help" 47 | BEGIN 48 | MENUITEM "&About ...", IDM_ABOUT 49 | END 50 | END 51 | 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // 55 | // Accelerator 56 | // 57 | 58 | IDC_MYPRIVATEBATCH ACCELERATORS 59 | BEGIN 60 | "?", IDM_ABOUT, ASCII, ALT 61 | "/", IDM_ABOUT, ASCII, ALT 62 | END 63 | 64 | 65 | ///////////////////////////////////////////////////////////////////////////// 66 | // 67 | // Dialog 68 | // 69 | 70 | IDD_ABOUTBOX DIALOG 22, 17, 230, 75 71 | STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU 72 | CAPTION "About" 73 | FONT 8, "System" 74 | BEGIN 75 | ICON IDI_MYPRIVATEBATCH,IDC_MYICON,14,9,16,16 76 | LTEXT "PrivateBatch Version 1.0",IDC_STATIC,49,10,119,8,SS_NOPREFIX 77 | LTEXT "Copyright (C) 2006",IDC_STATIC,49,20,119,8 78 | DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP 79 | END 80 | 81 | IDD_MAIN DIALOGEX 0, 0, 294, 201 82 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU 83 | CAPTION "Using a private thread pool" 84 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 85 | BEGIN 86 | PUSHBUTTON "Start batch",IDC_BTN_START_BATCH,90,7,59,14 87 | PUSHBUTTON "Run",IDC_BTN_RUN,153,7,50,14 88 | LISTBOX IDC_LB_STATUS,7,27,280,147,LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,WS_EX_STATICEDGE 89 | DEFPUSHBUTTON "&Exit",IDOK,237,180,50,14 90 | PUSHBUTTON "Create pool",IDC_BTN_CREATE_POOL,7,7,58,14 91 | PUSHBUTTON "Delete pool",IDC_BTN_DELETE_POOL,229,7,58,14 92 | END 93 | 94 | 95 | #ifdef APSTUDIO_INVOKED 96 | ///////////////////////////////////////////////////////////////////////////// 97 | // 98 | // TEXTINCLUDE 99 | // 100 | 101 | 1 TEXTINCLUDE 102 | BEGIN 103 | "resource.h\0" 104 | END 105 | 106 | 2 TEXTINCLUDE 107 | BEGIN 108 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 109 | "#include ""windows.h""\r\n" 110 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 111 | "\0" 112 | END 113 | 114 | 3 TEXTINCLUDE 115 | BEGIN 116 | "\r\n" 117 | "\0" 118 | END 119 | 120 | #endif // APSTUDIO_INVOKED 121 | 122 | 123 | ///////////////////////////////////////////////////////////////////////////// 124 | // 125 | // DESIGNINFO 126 | // 127 | 128 | #ifdef APSTUDIO_INVOKED 129 | GUIDELINES DESIGNINFO 130 | BEGIN 131 | IDD_MAIN, DIALOG 132 | BEGIN 133 | LEFTMARGIN, 7 134 | RIGHTMARGIN, 287 135 | TOPMARGIN, 7 136 | BOTTOMMARGIN, 194 137 | END 138 | END 139 | #endif // APSTUDIO_INVOKED 140 | 141 | 142 | ///////////////////////////////////////////////////////////////////////////// 143 | // 144 | // String Table 145 | // 146 | 147 | STRINGTABLE 148 | BEGIN 149 | IDS_APP_TITLE "PrivateBatch" 150 | IDC_MYPRIVATEBATCH "MYPRIVATEBATCH" 151 | END 152 | 153 | #endif // English (U.S.) resources 154 | ///////////////////////////////////////////////////////////////////////////// 155 | 156 | 157 | 158 | #ifndef APSTUDIO_INVOKED 159 | ///////////////////////////////////////////////////////////////////////////// 160 | // 161 | // Generated from the TEXTINCLUDE 3 resource. 162 | // 163 | 164 | 165 | ///////////////////////////////////////////////////////////////////////////// 166 | #endif // not APSTUDIO_INVOKED 167 | 168 | -------------------------------------------------------------------------------- /11-PrivateBatch/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by PrivateBatch.rc 4 | // 5 | #define IDC_MYICON 2 6 | #define IDD_MYPRIVATEBATCH_DIALOG 102 7 | #define IDS_APP_TITLE 103 8 | #define IDD_ABOUTBOX 103 9 | #define IDM_ABOUT 104 10 | #define IDM_EXIT 105 11 | #define IDI_MYPRIVATEBATCH 107 12 | #define IDI_SMALL 108 13 | #define IDC_MYPRIVATEBATCH 109 14 | #define IDR_MAINFRAME 128 15 | #define IDD_MAIN 129 16 | #define IDC_BTN_START_BATCH 1000 17 | #define IDC_LB_STATUS 1001 18 | #define IDC_BTN_RUN 1002 19 | #define IDC_BTN_CREATE_POOL 1003 20 | #define IDC_BTN_CREATE_POOL2 1004 21 | #define IDC_BTN_DELETE_POOL 1004 22 | #define IDC_STATIC -1 23 | 24 | // Next default values for new objects 25 | // 26 | #ifdef APSTUDIO_INVOKED 27 | #ifndef APSTUDIO_READONLY_SYMBOLS 28 | #define _APS_NO_MFC 1 29 | #define _APS_NEXT_RESOURCE_VALUE 129 30 | #define _APS_NEXT_COMMAND_VALUE 32771 31 | #define _APS_NEXT_CONTROL_VALUE 1003 32 | #define _APS_NEXT_SYMED_VALUE 110 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /11-TimedMsgBox/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by TimedMsgBox.rc 4 | // 5 | #define IDI_TIMEDMSGBOX 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /11-TimedMsgBox/TimedMsgBox.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: TimedMsgBox.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | 11 | 12 | ////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | // The caption of our message box 16 | TCHAR g_szCaption[100]; 17 | 18 | 19 | // How many seconds we'll display the message box 20 | int g_nSecLeft = 0; 21 | 22 | 23 | // This is STATIC window control ID for a message box 24 | #define ID_MSGBOX_STATIC_TEXT 0x0000ffff 25 | 26 | 27 | ////////////////////////////////////////////////////////////////////////////// 28 | 29 | 30 | VOID CALLBACK MsgBoxTimeoutCallback( 31 | PTP_CALLBACK_INSTANCE pInstance, 32 | PVOID pvContext, 33 | PTP_TIMER pTimer 34 | ) 35 | { 36 | // NOTE: Due to a thread race condition, it is possible (but very unlikely) 37 | // that the message box will not be created when we get here. 38 | HWND hwnd = FindWindow(NULL, g_szCaption); 39 | 40 | if (hwnd != NULL) { 41 | if (g_nSecLeft == 1) { 42 | // The time is up; force the message box to exit. 43 | EndDialog(hwnd, IDOK); 44 | return; 45 | } 46 | 47 | // The window does exist; update the time remaining. 48 | TCHAR szMsg[100]; 49 | StringCchPrintf(szMsg, _countof(szMsg), 50 | TEXT("You have %d seconds to respond"), --g_nSecLeft); 51 | SetDlgItemText(hwnd, ID_MSGBOX_STATIC_TEXT, szMsg); 52 | } else { 53 | 54 | // The window does not exist yet; do nothing this time. 55 | // We'll try again in another second. 56 | } 57 | } 58 | 59 | int WINAPI _tWinMain(HINSTANCE, HINSTANCE, PTSTR, int) { 60 | 61 | _tcscpy_s(g_szCaption, _countof(g_szCaption), TEXT("Timed Message Box")); 62 | 63 | // How many seconds we'll give the user to respond 64 | g_nSecLeft = 10; 65 | 66 | // Create the threadpool timer object 67 | PTP_TIMER lpTimer = 68 | CreateThreadpoolTimer(MsgBoxTimeoutCallback, NULL, NULL); 69 | 70 | if (lpTimer == NULL) { 71 | TCHAR szMsg[MAX_PATH]; 72 | StringCchPrintf(szMsg, _countof(szMsg), 73 | TEXT("Impossible to create the timer: %u"), GetLastError()); 74 | MessageBox(NULL, szMsg, TEXT("Error"), MB_OK | MB_ICONERROR); 75 | 76 | return(-1); 77 | } 78 | 79 | // Start the timer in one second to trigger every 1 second 80 | ULARGE_INTEGER ulRelativeStartTime; 81 | ulRelativeStartTime.QuadPart = (LONGLONG) -(10000000); // start in 1 second 82 | FILETIME ftRelativeStartTime; 83 | ftRelativeStartTime.dwHighDateTime = ulRelativeStartTime.HighPart; 84 | ftRelativeStartTime.dwLowDateTime = ulRelativeStartTime.LowPart; 85 | SetThreadpoolTimer( 86 | lpTimer, 87 | &ftRelativeStartTime, 88 | 1000, // Triggers every 1000 milliseconds 89 | 0 90 | ); 91 | 92 | // Display the message box 93 | MessageBox(NULL, TEXT("You have 10 seconds to respond"), 94 | g_szCaption, MB_OK); 95 | 96 | // Clean up the timer 97 | CloseThreadpoolTimer(lpTimer); 98 | 99 | // Let us know if the user responded or if we timed out 100 | MessageBox( 101 | NULL, (g_nSecLeft == 1) ? TEXT("Timeout") : TEXT("User responded"), 102 | TEXT("Result"), MB_OK); 103 | 104 | return(0); 105 | } 106 | 107 | 108 | //////////////////////////////// End of File ///////////////////////////////// 109 | -------------------------------------------------------------------------------- /11-TimedMsgBox/TimedMsgBox.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/11-TimedMsgBox/TimedMsgBox.ico -------------------------------------------------------------------------------- /11-TimedMsgBox/TimedMsgBox.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_TIMEDMSGBOX ICON DISCARDABLE "TimedMsgBox.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | #endif // English (U.S.) resources 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | 63 | #ifndef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Generated from the TEXTINCLUDE 3 resource. 67 | // 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | #endif // not APSTUDIO_INVOKED 72 | 73 | -------------------------------------------------------------------------------- /12-Counter/Counter.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/12-Counter/Counter.ico -------------------------------------------------------------------------------- /12-Counter/Counter.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_COUNTER DIALOG DISCARDABLE 0, 0, 156, 37 30 | STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | 31 | WS_SYSMENU 32 | CAPTION "Counter" 33 | FONT 8, "MS Sans Serif" 34 | BEGIN 35 | LTEXT "Count to:",IDC_STATIC,4,6,34,8 36 | EDITTEXT IDC_COUNT,38,4,40,14,ES_AUTOHSCROLL | ES_NUMBER 37 | LTEXT "Answer:",IDC_STATIC,90,6,25,8 38 | RTEXT "0",IDC_ANSWER,122,6,23,8 39 | LTEXT "Currently running fiber:",IDC_STATIC,4,24,75,8 40 | LTEXT "Fiber",IDC_FIBER,80,24,72,8 41 | END 42 | 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // 46 | // DESIGNINFO 47 | // 48 | 49 | #ifdef APSTUDIO_INVOKED 50 | GUIDELINES DESIGNINFO DISCARDABLE 51 | BEGIN 52 | IDD_COUNTER, DIALOG 53 | BEGIN 54 | LEFTMARGIN, 7 55 | RIGHTMARGIN, 149 56 | TOPMARGIN, 7 57 | BOTTOMMARGIN, 30 58 | END 59 | END 60 | #endif // APSTUDIO_INVOKED 61 | 62 | 63 | #ifdef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // TEXTINCLUDE 67 | // 68 | 69 | 1 TEXTINCLUDE DISCARDABLE 70 | BEGIN 71 | "resource.h\0" 72 | END 73 | 74 | 2 TEXTINCLUDE DISCARDABLE 75 | BEGIN 76 | "#include ""Windows.h""\r\n" 77 | "\0" 78 | END 79 | 80 | 3 TEXTINCLUDE DISCARDABLE 81 | BEGIN 82 | "\r\n" 83 | "\0" 84 | END 85 | 86 | #endif // APSTUDIO_INVOKED 87 | 88 | 89 | ///////////////////////////////////////////////////////////////////////////// 90 | // 91 | // Icon 92 | // 93 | 94 | // Icon with lowest ID value placed first to ensure application icon 95 | // remains consistent on all systems. 96 | IDI_COUNTER ICON DISCARDABLE "Counter.ico" 97 | #endif // English (U.S.) resources 98 | ///////////////////////////////////////////////////////////////////////////// 99 | 100 | 101 | 102 | #ifndef APSTUDIO_INVOKED 103 | ///////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Generated from the TEXTINCLUDE 3 resource. 106 | // 107 | 108 | 109 | ///////////////////////////////////////////////////////////////////////////// 110 | #endif // not APSTUDIO_INVOKED 111 | 112 | -------------------------------------------------------------------------------- /12-Counter/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Counter.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_COUNTER 101 7 | #define IDI_COUNTER 102 8 | #define IDC_FIBER 1000 9 | #define IDC_ANSWER 1001 10 | #define IDC_COUNT 1002 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 103 17 | #define _APS_NEXT_COMMAND_VALUE 40001 18 | #define _APS_NEXT_CONTROL_VALUE 1003 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /14-SysInfo/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by SYSINFO.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_SYSINFO 1 7 | #define IDC_PROCARCH 100 8 | #define IDC_PAGESIZE 101 9 | #define IDI_SYSINFO 101 10 | #define IDC_MINAPPADDR 102 11 | #define IDC_MAXAPPADDR 103 12 | #define IDC_ACTIVEPROCMASK 104 13 | #define IDC_NUMOFPROCS 105 14 | #define IDC_PROCTYPE 106 15 | #define IDC_ALLOCGRAN 107 16 | #define IDC_PROCLEVEL 108 17 | #define IDC_PROCREV 109 18 | 19 | // Next default values for new objects 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | #define _APS_NEXT_RESOURCE_VALUE 102 24 | #define _APS_NEXT_COMMAND_VALUE 40001 25 | #define _APS_NEXT_CONTROL_VALUE 1000 26 | #define _APS_NEXT_SYMED_VALUE 101 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /14-SysInfo/SysInfo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/14-SysInfo/SysInfo.ico -------------------------------------------------------------------------------- /14-SysInfo/SysInfo.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_SYSINFO DIALOGEX 18, 18, 210, 97 56 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "Sys Info" 58 | FONT 8, "MS Sans Serif", 0, 0, 0x0 59 | BEGIN 60 | RTEXT "Processor Architecture:",IDC_STATIC,8,4,88,8,SS_NOPREFIX 61 | RTEXT "ID_PROCARCH",IDC_PROCARCH,111,4,84,8,SS_NOPREFIX 62 | RTEXT "Processor level:",IDC_STATIC,8,14,88,8,SS_NOPREFIX 63 | RTEXT "ID_PROCLEVEL",IDC_PROCLEVEL,111,14,84,8,SS_NOPREFIX 64 | RTEXT "Processor revision:",IDC_STATIC,8,24,88,8,SS_NOPREFIX 65 | RTEXT "ID_PROCREV",IDC_PROCREV,111,24,84,8,SS_NOPREFIX 66 | RTEXT "Number of processors:",IDC_STATIC,8,34,88,8,SS_NOPREFIX 67 | RTEXT "ID_NUMOFPROCS",IDC_NUMOFPROCS,111,34,84,8,SS_NOPREFIX 68 | RTEXT "Active processor mask:",IDC_STATIC,8,44,88,8,SS_NOPREFIX 69 | RTEXT "ID_ACTIVEPROCMASK",IDC_ACTIVEPROCMASK,111,44,84,8,SS_NOPREFIX 70 | RTEXT "Allocation granularity:",IDC_STATIC,8,54,88,8,SS_NOPREFIX 71 | RTEXT "ID_ALLOCGRAN",IDC_ALLOCGRAN,111,54,84,8,SS_NOPREFIX 72 | RTEXT "Page size:",IDC_STATIC,8,64,88,8,SS_NOPREFIX 73 | RTEXT "ID_PAGESIZE",IDC_PAGESIZE,111,64,84,8,SS_NOPREFIX 74 | RTEXT "Minimum app. address:",IDC_STATIC,8,74,88,8,SS_NOPREFIX 75 | RTEXT "ID_MINAPPADDR",IDC_MINAPPADDR,111,74,84,8,SS_NOPREFIX 76 | RTEXT "Maximum app. address:",IDC_STATIC,8,84,88,8,SS_NOPREFIX 77 | RTEXT "ID_MAXAPPADDR",IDC_MAXAPPADDR,111,84,84,8,SS_NOPREFIX 78 | END 79 | 80 | 81 | ///////////////////////////////////////////////////////////////////////////// 82 | // 83 | // Icon 84 | // 85 | 86 | // Icon with lowest ID value placed first to ensure application icon 87 | // remains consistent on all systems. 88 | IDI_SYSINFO ICON "SysInfo.Ico" 89 | 90 | ///////////////////////////////////////////////////////////////////////////// 91 | // 92 | // DESIGNINFO 93 | // 94 | 95 | #ifdef APSTUDIO_INVOKED 96 | GUIDELINES DESIGNINFO 97 | BEGIN 98 | IDD_SYSINFO, DIALOG 99 | BEGIN 100 | RIGHTMARGIN, 194 101 | BOTTOMMARGIN, 77 102 | END 103 | END 104 | #endif // APSTUDIO_INVOKED 105 | 106 | #endif // English (U.S.) resources 107 | ///////////////////////////////////////////////////////////////////////////// 108 | 109 | 110 | 111 | #ifndef APSTUDIO_INVOKED 112 | ///////////////////////////////////////////////////////////////////////////// 113 | // 114 | // Generated from the TEXTINCLUDE 3 resource. 115 | // 116 | 117 | 118 | ///////////////////////////////////////////////////////////////////////////// 119 | #endif // not APSTUDIO_INVOKED 120 | 121 | -------------------------------------------------------------------------------- /14-VMMap/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by VMMap.rc 4 | // 5 | #define IDD_VMMAP 1 6 | #define IDC_LISTBOX 100 7 | #define IDI_VMMAP 101 8 | #define IDR_VMMAP 102 9 | #define ID_REFRESH 40001 10 | #define ID_EXPANDREGIONS 40002 11 | #define ID_COPYTOCLIPBOARD 40003 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 102 18 | #define _APS_NEXT_COMMAND_VALUE 40004 19 | #define _APS_NEXT_CONTROL_VALUE 1000 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /14-VMMap/VMMap.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/14-VMMap/VMMap.ico -------------------------------------------------------------------------------- /14-VMMap/VMMap.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_VMMAP DIALOGEX 10, 18, 250, 250 56 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 57 | CAPTION "Virtual Memory Map" 58 | MENU IDR_VMMAP 59 | FONT 8, "Courier", 0, 0, 0x0 60 | BEGIN 61 | LISTBOX IDC_LISTBOX,0,0,248,248,LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_GROUP | WS_TABSTOP 62 | END 63 | 64 | 65 | ///////////////////////////////////////////////////////////////////////////// 66 | // 67 | // Icon 68 | // 69 | 70 | // Icon with lowest ID value placed first to ensure application icon 71 | // remains consistent on all systems. 72 | IDI_VMMAP ICON "VMMap.Ico" 73 | 74 | ///////////////////////////////////////////////////////////////////////////// 75 | // 76 | // Menu 77 | // 78 | 79 | IDR_VMMAP MENU 80 | BEGIN 81 | MENUITEM "&Refresh!", ID_REFRESH 82 | MENUITEM "&Expand Regions!", ID_EXPANDREGIONS 83 | MENUITEM "&Copy to Clipboard!", ID_COPYTOCLIPBOARD 84 | END 85 | 86 | #endif // English (U.S.) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /14-VMMap/VMQuery.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: VMQuery.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | typedef struct { 8 | // Region information 9 | PVOID pvRgnBaseAddress; 10 | DWORD dwRgnProtection; // PAGE_* 11 | SIZE_T RgnSize; 12 | DWORD dwRgnStorage; // MEM_*: Free, Image, Mapped, Private 13 | DWORD dwRgnBlocks; 14 | DWORD dwRgnGuardBlks; // If > 0, region contains thread stack 15 | BOOL bRgnIsAStack; // TRUE if region contains thread stack 16 | 17 | // Block information 18 | PVOID pvBlkBaseAddress; 19 | DWORD dwBlkProtection; // PAGE_* 20 | SIZE_T BlkSize; 21 | DWORD dwBlkStorage; // MEM_*: Free, Reserve, Image, Mapped, Private 22 | } VMQUERY, *PVMQUERY; 23 | 24 | 25 | /////////////////////////////////////////////////////////////////////////////// 26 | 27 | 28 | BOOL VMQuery(HANDLE hProcess, LPCVOID pvAddress, PVMQUERY pVMQ); 29 | 30 | 31 | //////////////////////////////// End of File ////////////////////////////////// 32 | -------------------------------------------------------------------------------- /14-VMStat/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by VMStat.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_VMSTAT 1 7 | #define IDI_VMSTAT 101 8 | #define IDC_DATA 1000 9 | #define IDC_WORKINGSET 1001 10 | #define IDC_PROCESSDATA 1001 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 102 17 | #define _APS_NEXT_COMMAND_VALUE 40001 18 | #define _APS_NEXT_CONTROL_VALUE 1002 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /14-VMStat/VMStat.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: VMStat.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include 11 | #include "Resource.h" 12 | #include 13 | #include 14 | 15 | 16 | // Look for the .lib corresponding to psapi.dll 17 | #pragma comment (lib,"psapi.lib") 18 | 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | 22 | 23 | // The update timer's ID 24 | #define IDT_UPDATE 1 25 | 26 | 27 | /////////////////////////////////////////////////////////////////////////////// 28 | 29 | 30 | BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { 31 | 32 | chSETDLGICONS(hwnd, IDI_VMSTAT); 33 | 34 | // Set a timer so that the information updates periodically. 35 | SetTimer(hwnd, IDT_UPDATE, 1 * 1000, NULL); 36 | 37 | // Force a timer message for the initial update. 38 | FORWARD_WM_TIMER(hwnd, IDT_UPDATE, SendMessage); 39 | return(TRUE); 40 | } 41 | 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | 45 | 46 | void Dlg_OnTimer(HWND hwnd, UINT id) { 47 | 48 | // Initialize the structure length before calling GlobalMemoryStatus. 49 | MEMORYSTATUS ms = { sizeof(ms) }; 50 | GlobalMemoryStatus(&ms); 51 | 52 | TCHAR szData[512] = { 0 }; 53 | StringCchPrintf(szData, _countof(szData), 54 | TEXT("%d\n%d\n%I64d\n%I64d\n%I64d\n%I64d\n%I64d"), 55 | ms.dwMemoryLoad, ms.dwTotalPhys, 56 | (__int64) ms.dwAvailPhys, (__int64) ms.dwTotalPageFile, 57 | (__int64) ms.dwAvailPageFile, (__int64) ms.dwTotalVirtual, 58 | (__int64) ms.dwAvailVirtual); 59 | 60 | SetDlgItemText(hwnd, IDC_DATA, szData); 61 | 62 | // Get the current process working set and private bytes. 63 | PROCESS_MEMORY_COUNTERS_EX pmc = { sizeof(PROCESS_MEMORY_COUNTERS_EX) }; 64 | GetProcessMemoryInfo(GetCurrentProcess(), (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc)); 65 | StringCchPrintf(szData, _countof(szData), 66 | TEXT("%I64d K\n%I64d K"), 67 | (__int64) pmc.WorkingSetSize / 1024, 68 | (__int64) pmc.PrivateUsage / 1024); 69 | SetDlgItemText(hwnd, IDC_PROCESSDATA, szData); 70 | } 71 | 72 | 73 | /////////////////////////////////////////////////////////////////////////////// 74 | 75 | 76 | void Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { 77 | 78 | switch (id) { 79 | case IDCANCEL: 80 | KillTimer(hwnd, IDT_UPDATE); 81 | EndDialog(hwnd, id); 82 | break; 83 | } 84 | } 85 | 86 | 87 | /////////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 91 | 92 | switch (uMsg) { 93 | chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog); 94 | chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand); 95 | chHANDLE_DLGMSG(hwnd, WM_TIMER, Dlg_OnTimer); 96 | } 97 | return(FALSE); 98 | } 99 | 100 | 101 | /////////////////////////////////////////////////////////////////////////////// 102 | 103 | 104 | int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) { 105 | 106 | DialogBox(hinstExe, MAKEINTRESOURCE(IDD_VMSTAT), NULL, Dlg_Proc); 107 | return(0); 108 | } 109 | 110 | 111 | 112 | 113 | //////////////////////////////// End of File ////////////////////////////////// 114 | -------------------------------------------------------------------------------- /14-VMStat/VMStat.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/14-VMStat/VMStat.ico -------------------------------------------------------------------------------- /14-VMStat/VMStat.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_VMSTAT DIALOGEX 60, 60, 127, 97 56 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "VMStat" 58 | FONT 8, "MS Sans Serif", 0, 0, 0x0 59 | BEGIN 60 | LTEXT "Memory load:\nTotalPhys:\nAvailPhys:\nTotalPageFile:\nAvailPageFile:\nTotalVirtual:\nAvailVirtual:",IDC_STATIC,2,5,51,56,0,WS_EX_RIGHT 61 | RTEXT "Memory load:\nTotalPhys:\nAvailPhys:\nTotalPageFile:\nAvailPageFile:\nTotalVirtual:\nAvailVirtual:",IDC_DATA,56,5,61,56 62 | LTEXT "WorkingSet:\nPrivateBytes:",IDC_STATIC,2,74,51,17,0,WS_EX_RIGHT 63 | LTEXT "WorkingSet:\nPrivateBytes:",IDC_PROCESSDATA,56,74,61,17,0,WS_EX_RIGHT 64 | CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,7,67,115,1 65 | END 66 | 67 | 68 | ///////////////////////////////////////////////////////////////////////////// 69 | // 70 | // Icon 71 | // 72 | 73 | // Icon with lowest ID value placed first to ensure application icon 74 | // remains consistent on all systems. 75 | IDI_VMSTAT ICON "VMStat.Ico" 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // DESIGNINFO 80 | // 81 | 82 | #ifdef APSTUDIO_INVOKED 83 | GUIDELINES DESIGNINFO 84 | BEGIN 85 | IDD_VMSTAT, DIALOG 86 | BEGIN 87 | RIGHTMARGIN, 103 88 | BOTTOMMARGIN, 96 89 | END 90 | END 91 | #endif // APSTUDIO_INVOKED 92 | 93 | #endif // English (U.S.) resources 94 | ///////////////////////////////////////////////////////////////////////////// 95 | 96 | 97 | 98 | #ifndef APSTUDIO_INVOKED 99 | ///////////////////////////////////////////////////////////////////////////// 100 | // 101 | // Generated from the TEXTINCLUDE 3 resource. 102 | // 103 | 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | #endif // not APSTUDIO_INVOKED 107 | 108 | -------------------------------------------------------------------------------- /15-AWE/15-AWE.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /15-AWE/AWE.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: AWE.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "AddrWindow.h" 11 | #include "Resource.h" 12 | #include 13 | 14 | 15 | /////////////////////////////////////////////////////////////////////////////// 16 | 17 | 18 | CAddrWindow g_aw[2]; // 2 memory address windows 19 | CAddrWindowStorage g_aws[2]; // 2 storage blocks 20 | const ULONG_PTR g_nChars = 1024; // 1024 character buffers 21 | const DWORD g_cbBufferSize = g_nChars * sizeof(TCHAR); 22 | 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | 26 | 27 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 28 | 29 | chSETDLGICONS(hWnd, IDI_AWE); 30 | 31 | // Create the 2 memory address windows 32 | chVERIFY(g_aw[0].Create(g_cbBufferSize)); 33 | chVERIFY(g_aw[1].Create(g_cbBufferSize)); 34 | 35 | // Create the 2 storage blocks 36 | if (!g_aws[0].Allocate(g_cbBufferSize)) { 37 | chFAIL("Failed to allocate RAM.\nMost likely reason: " 38 | "you are not granted the Lock Pages in Memory user right."); 39 | } 40 | chVERIFY(g_aws[1].Allocate(g_nChars * sizeof(TCHAR))); 41 | 42 | // Put some default text in the 1st storage block 43 | g_aws[0].MapStorage(g_aw[0]); 44 | _tcscpy_s((PTSTR) (PVOID) g_aw[0], g_cbBufferSize, TEXT("Text in Storage 0")); 45 | 46 | // Put some default text in the 2nd storage block 47 | g_aws[1].MapStorage(g_aw[0]); 48 | _tcscpy_s((PTSTR) (PVOID) g_aw[0], g_cbBufferSize, TEXT("Text in Storage 1")); 49 | 50 | // Populate the dialog box controls 51 | for (int n = 0; n <= 1; n++) { 52 | // Set the combo box for each address window 53 | int id = ((n == 0) ? IDC_WINDOW0STORAGE : IDC_WINDOW1STORAGE); 54 | HWND hWndCB = GetDlgItem(hWnd, id); 55 | ComboBox_AddString(hWndCB, TEXT("No storage")); 56 | ComboBox_AddString(hWndCB, TEXT("Storage 0")); 57 | ComboBox_AddString(hWndCB, TEXT("Storage 1")); 58 | 59 | // Window 0 shows Storage 0, Window 1 shows Storage 1 60 | ComboBox_SetCurSel(hWndCB, n + 1); 61 | FORWARD_WM_COMMAND(hWnd, id, hWndCB, CBN_SELCHANGE, SendMessage); 62 | Edit_LimitText(GetDlgItem(hWnd, 63 | (n == 0) ? IDC_WINDOW0TEXT : IDC_WINDOW1TEXT), g_nChars); 64 | } 65 | 66 | return(TRUE); 67 | } 68 | 69 | 70 | /////////////////////////////////////////////////////////////////////////////// 71 | 72 | 73 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 74 | 75 | switch (id) { 76 | 77 | case IDCANCEL: 78 | EndDialog(hWnd, id); 79 | break; 80 | 81 | case IDC_WINDOW0STORAGE: 82 | case IDC_WINDOW1STORAGE: 83 | if (codeNotify == CBN_SELCHANGE) { 84 | 85 | // Show different storage in address window 86 | int nWindow = ((id == IDC_WINDOW0STORAGE) ? 0 : 1); 87 | int nStorage = ComboBox_GetCurSel(hWndCtl) - 1; 88 | 89 | if (nStorage == -1) { // Show no storage in this window 90 | chVERIFY(g_aw[nWindow].UnmapStorage()); 91 | } else { 92 | if (!g_aws[nStorage].MapStorage(g_aw[nWindow])) { 93 | // Couldn't map storage in window 94 | chVERIFY(g_aw[nWindow].UnmapStorage()); 95 | ComboBox_SetCurSel(hWndCtl, 0); // Force "No storage" 96 | chMB("This storage can be mapped only once."); 97 | } 98 | } 99 | 100 | // Update the address window's text display 101 | HWND hWndText = GetDlgItem(hWnd, 102 | ((nWindow == 0) ? IDC_WINDOW0TEXT : IDC_WINDOW1TEXT)); 103 | MEMORY_BASIC_INFORMATION mbi; 104 | VirtualQuery(g_aw[nWindow], &mbi, sizeof(mbi)); 105 | // Note: mbi.State == MEM_RESERVE if no storage is in address window 106 | EnableWindow(hWndText, (mbi.State == MEM_COMMIT)); 107 | Edit_SetText(hWndText, IsWindowEnabled(hWndText) 108 | ? (PCTSTR) (PVOID) g_aw[nWindow] : TEXT("(No storage)")); 109 | } 110 | break; 111 | 112 | case IDC_WINDOW0TEXT: 113 | case IDC_WINDOW1TEXT: 114 | if (codeNotify == EN_CHANGE) { 115 | // Update the storage in the address window 116 | int nWindow = ((id == IDC_WINDOW0TEXT) ? 0 : 1); 117 | Edit_GetText(hWndCtl, (PTSTR) (PVOID) g_aw[nWindow], g_nChars); 118 | } 119 | break; 120 | } 121 | } 122 | 123 | 124 | /////////////////////////////////////////////////////////////////////////////// 125 | 126 | 127 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 128 | 129 | switch (uMsg) { 130 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 131 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 132 | } 133 | 134 | return(FALSE); 135 | } 136 | 137 | 138 | /////////////////////////////////////////////////////////////////////////////// 139 | 140 | 141 | 142 | int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR, int) { 143 | 144 | DialogBox(hInstExe, MAKEINTRESOURCE(IDD_AWE), NULL, Dlg_Proc); 145 | return(0); 146 | } 147 | 148 | 149 | //////////////////////////////// End of File ////////////////////////////////// 150 | -------------------------------------------------------------------------------- /15-AWE/AWE.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/15-AWE/AWE.ico -------------------------------------------------------------------------------- /15-AWE/AWE.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_AWE DIALOG DISCARDABLE 0, 0, 288, 45 30 | STYLE DS_SETFOREGROUND | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | 31 | WS_CAPTION | WS_SYSMENU 32 | CAPTION "Address Windowing Extensions" 33 | FONT 8, "MS Sans Serif" 34 | BEGIN 35 | LTEXT "Window 0:",IDC_STATIC,4,6,35,8 36 | COMBOBOX IDC_WINDOW0STORAGE,44,4,80,58,CBS_DROPDOWNLIST | 37 | WS_TABSTOP 38 | EDITTEXT IDC_WINDOW0TEXT,132,4,152,14,ES_AUTOHSCROLL 39 | LTEXT "Window 1:",IDC_STATIC,4,28,35,8 40 | COMBOBOX IDC_WINDOW1STORAGE,44,25,80,58,CBS_DROPDOWNLIST | 41 | WS_TABSTOP 42 | EDITTEXT IDC_WINDOW1TEXT,132,25,152,14,ES_AUTOHSCROLL 43 | END 44 | 45 | 46 | ///////////////////////////////////////////////////////////////////////////// 47 | // 48 | // DESIGNINFO 49 | // 50 | 51 | #ifdef APSTUDIO_INVOKED 52 | GUIDELINES DESIGNINFO DISCARDABLE 53 | BEGIN 54 | IDD_AWE, DIALOG 55 | BEGIN 56 | LEFTMARGIN, 7 57 | RIGHTMARGIN, 281 58 | TOPMARGIN, 7 59 | BOTTOMMARGIN, 38 60 | END 61 | END 62 | #endif // APSTUDIO_INVOKED 63 | 64 | 65 | #ifdef APSTUDIO_INVOKED 66 | ///////////////////////////////////////////////////////////////////////////// 67 | // 68 | // TEXTINCLUDE 69 | // 70 | 71 | 1 TEXTINCLUDE DISCARDABLE 72 | BEGIN 73 | "resource.h\0" 74 | END 75 | 76 | 2 TEXTINCLUDE DISCARDABLE 77 | BEGIN 78 | "#include ""Windows.h""\r\n" 79 | "\0" 80 | END 81 | 82 | 3 TEXTINCLUDE DISCARDABLE 83 | BEGIN 84 | "\r\n" 85 | "\0" 86 | END 87 | 88 | #endif // APSTUDIO_INVOKED 89 | 90 | 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Icon 94 | // 95 | 96 | // Icon with lowest ID value placed first to ensure application icon 97 | // remains consistent on all systems. 98 | IDI_AWE ICON DISCARDABLE "AWE.ico" 99 | #endif // English (U.S.) resources 100 | ///////////////////////////////////////////////////////////////////////////// 101 | 102 | 103 | 104 | #ifndef APSTUDIO_INVOKED 105 | ///////////////////////////////////////////////////////////////////////////// 106 | // 107 | // Generated from the TEXTINCLUDE 3 resource. 108 | // 109 | 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | #endif // not APSTUDIO_INVOKED 113 | 114 | -------------------------------------------------------------------------------- /15-AWE/AddrWindow.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: AddrWindow.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #pragma once 8 | 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | 13 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 14 | #include 15 | 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | class CSystemInfo : public SYSTEM_INFO { 21 | public: 22 | CSystemInfo() { GetSystemInfo(this); } 23 | }; 24 | 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | 28 | 29 | class CAddrWindow { 30 | public: 31 | CAddrWindow() { m_pvWindow = NULL; } 32 | ~CAddrWindow() { Destroy(); } 33 | 34 | BOOL Create(SIZE_T dwBytes, PVOID pvPreferredWindowBase = NULL) { 35 | // Reserve address window region to view physical storage 36 | m_pvWindow = VirtualAlloc(pvPreferredWindowBase, dwBytes, 37 | MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE); 38 | return(m_pvWindow != NULL); 39 | } 40 | 41 | BOOL Destroy() { 42 | BOOL bOk = TRUE; 43 | if (m_pvWindow != NULL) { 44 | // Destroy address window region 45 | bOk = VirtualFree(m_pvWindow, 0, MEM_RELEASE); 46 | m_pvWindow = NULL; 47 | } 48 | return(bOk); 49 | } 50 | 51 | BOOL UnmapStorage() { 52 | // Unmap all storage from address window region 53 | MEMORY_BASIC_INFORMATION mbi; 54 | VirtualQuery(m_pvWindow, &mbi, sizeof(mbi)); 55 | return(MapUserPhysicalPages(m_pvWindow, 56 | mbi.RegionSize / sm_sinf.dwPageSize, NULL)); 57 | } 58 | 59 | // Returns virtual address of address window 60 | operator PVOID() { return(m_pvWindow); } 61 | 62 | private: 63 | PVOID m_pvWindow; // Virtual address of address window region 64 | static CSystemInfo sm_sinf; 65 | }; 66 | 67 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | 70 | 71 | CSystemInfo CAddrWindow::sm_sinf; 72 | 73 | 74 | /////////////////////////////////////////////////////////////////////////////// 75 | 76 | 77 | class CAddrWindowStorage { 78 | public: 79 | CAddrWindowStorage() { m_ulPages = 0; m_pulUserPfnArray = NULL; } 80 | ~CAddrWindowStorage() { Free(); } 81 | 82 | BOOL Allocate(ULONG_PTR ulBytes) { 83 | // Allocate storage intended for an address window 84 | 85 | Free(); // Clean up this object's existing address window 86 | 87 | // Calculate number of pages from number of bytes 88 | m_ulPages = (ulBytes + sm_sinf.dwPageSize - 1) / sm_sinf.dwPageSize; 89 | 90 | // Allocate array of page frame numbers 91 | m_pulUserPfnArray = (PULONG_PTR) 92 | HeapAlloc(GetProcessHeap(), 0, m_ulPages * sizeof(ULONG_PTR)); 93 | 94 | BOOL bOk = (m_pulUserPfnArray != NULL); 95 | if (bOk) { 96 | // The "Lock Pages in Memory" privilege must be enabled 97 | EnablePrivilege(SE_LOCK_MEMORY_NAME, TRUE); 98 | bOk = AllocateUserPhysicalPages(GetCurrentProcess(), 99 | &m_ulPages, m_pulUserPfnArray); 100 | EnablePrivilege(SE_LOCK_MEMORY_NAME, FALSE); 101 | } 102 | return(bOk); 103 | } 104 | 105 | BOOL Free() { 106 | BOOL bOk = TRUE; 107 | if (m_pulUserPfnArray != NULL) { 108 | bOk = FreeUserPhysicalPages(GetCurrentProcess(), 109 | &m_ulPages, m_pulUserPfnArray); 110 | if (bOk) { 111 | // Free the array of page frame numbers 112 | HeapFree(GetProcessHeap(), 0, m_pulUserPfnArray); 113 | m_ulPages = 0; 114 | m_pulUserPfnArray = NULL; 115 | } 116 | } 117 | return(bOk); 118 | } 119 | 120 | ULONG_PTR HowManyPagesAllocated() { return(m_ulPages); } 121 | 122 | BOOL MapStorage(CAddrWindow& aw) { 123 | return(MapUserPhysicalPages(aw, 124 | HowManyPagesAllocated(), m_pulUserPfnArray)); 125 | } 126 | 127 | BOOL UnmapStorage(CAddrWindow& aw) { 128 | return(MapUserPhysicalPages(aw, 129 | HowManyPagesAllocated(), NULL)); 130 | } 131 | 132 | private: 133 | static BOOL EnablePrivilege(PCTSTR pszPrivName, BOOL bEnable = TRUE) { 134 | 135 | BOOL bOk = FALSE; // Assume function fails 136 | HANDLE hToken; 137 | 138 | // Try to open this process' access token 139 | if (OpenProcessToken(GetCurrentProcess(), 140 | TOKEN_ADJUST_PRIVILEGES, &hToken)) { 141 | 142 | // Attempt to modify the "Lock pages in Memory" privilege 143 | TOKEN_PRIVILEGES tp = { 1 }; 144 | LookupPrivilegeValue(NULL, pszPrivName, &tp.Privileges[0].Luid); 145 | tp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0; 146 | AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL); 147 | bOk = (GetLastError() == ERROR_SUCCESS); 148 | CloseHandle(hToken); 149 | } 150 | return(bOk); 151 | } 152 | 153 | private: 154 | ULONG_PTR m_ulPages; // Number of storage pages 155 | PULONG_PTR m_pulUserPfnArray; // Page frame number array 156 | 157 | private: 158 | static CSystemInfo sm_sinf; 159 | }; 160 | 161 | 162 | /////////////////////////////////////////////////////////////////////////////// 163 | 164 | 165 | CSystemInfo CAddrWindowStorage::sm_sinf; 166 | 167 | 168 | //////////////////////////////// End of File ////////////////////////////////// 169 | -------------------------------------------------------------------------------- /15-AWE/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by AWE.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_AWE 101 7 | #define IDI_AWE 104 8 | #define IDC_WINDOW0TEXT 1006 9 | #define IDC_WINDOW0STORAGE 1007 10 | #define IDC_WINDOW1STORAGE 1008 11 | #define IDC_WINDOW1TEXT 1009 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 105 18 | #define _APS_NEXT_COMMAND_VALUE 40001 19 | #define _APS_NEXT_CONTROL_VALUE 1008 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /15-MemReset/MemReset.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: MemReset.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | 14 | int WINAPI _tWinMain(HINSTANCE, HINSTANCE, PTSTR, int) { 15 | 16 | TCHAR szAppName[] = TEXT("MEM_RESET tester"); 17 | TCHAR szTestData[] = TEXT("Some text data"); 18 | 19 | // Commit a page of storage and modify its contents. 20 | PTSTR pszData = (PTSTR) VirtualAlloc(NULL, 1024, 21 | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 22 | _tcscpy_s(pszData, 1024, szTestData); 23 | 24 | if (MessageBox(NULL, TEXT("Do you want to access this data later?"), 25 | szAppName, MB_YESNO) == IDNO) { 26 | 27 | // We want this page of storage to remain in our process but the 28 | // contents aren't important to us anymore. 29 | // Tell the system that the data is not modified. 30 | 31 | // Note: Because MEM_RESET destroys data, VirtualAlloc rounds 32 | // the base address and size parameters to their safest range. 33 | // Here is an example: 34 | // VirtualAlloc(pvData, 5000, MEM_RESET, PAGE_READWRITE) 35 | // resets 0 pages on CPUs where the page size is greater than 4 KB 36 | // and resets 1 page on CPUs with a 4 KB page. So that our call to 37 | // VirtualAlloc to reset memory below always succeeds, VirtualQuery 38 | // is called first to get the exact region size. 39 | MEMORY_BASIC_INFORMATION mbi; 40 | VirtualQuery(pszData, &mbi, sizeof(mbi)); 41 | VirtualAlloc(pszData, mbi.RegionSize, MEM_RESET, PAGE_READWRITE); 42 | } 43 | 44 | // Commit as much storage as there is physical RAM. 45 | MEMORYSTATUS mst; 46 | GlobalMemoryStatus(&mst); 47 | PVOID pvDummy = VirtualAlloc(NULL, mst.dwTotalPhys, 48 | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 49 | 50 | // Touch all the pages in the dummy region so that any 51 | // modified pages in RAM are written to the paging file. 52 | if (pvDummy != NULL) 53 | ZeroMemory(pvDummy, mst.dwTotalPhys); 54 | 55 | // Compare our data page with what we originally wrote there. 56 | if (_tcscmp(pszData, szTestData) == 0) { 57 | 58 | // The data in the page matches what we originally put there. 59 | // ZeroMemory forced our page to be written to the paging file. 60 | MessageBox(NULL, TEXT("Modified data page was saved."), 61 | szAppName, MB_OK); 62 | } else { 63 | 64 | // The data in the page does NOT match what we originally put there 65 | // ZeroMemory didn't cause our page to be written to the paging file 66 | MessageBox(NULL, TEXT("Modified data page was NOT saved."), 67 | szAppName, MB_OK); 68 | } 69 | 70 | // Don't forget to release part of the address space. 71 | // Note that it is not mandatory here since the application is exiting. 72 | if (pvDummy != NULL) 73 | VirtualFree(pvDummy, 0, MEM_RELEASE); 74 | VirtualFree(pszData, 0, MEM_RELEASE); 75 | 76 | return(0); 77 | } 78 | 79 | 80 | //////////////////////////////// End of File ////////////////////////////////// 81 | -------------------------------------------------------------------------------- /15-MemReset/MemReset.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/15-MemReset/MemReset.ico -------------------------------------------------------------------------------- /15-MemReset/MemReset.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_MEMRESET ICON DISCARDABLE "MemReset.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | #endif // English (U.S.) resources 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | 63 | #ifndef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Generated from the TEXTINCLUDE 3 resource. 67 | // 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | #endif // not APSTUDIO_INVOKED 72 | 73 | -------------------------------------------------------------------------------- /15-MemReset/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by MemReset.rc 4 | // 5 | #define IDI_MEMRESET 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /15-VMAlloc/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by VMALLOC.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_VMALLOC 1 7 | #define IDC_PAGESIZE 100 8 | #define IDC_RESERVE 101 9 | #define IDI_VMALLOC 101 10 | #define IDC_INDEXTEXT 102 11 | #define IDC_INDEX 103 12 | #define IDC_USE 105 13 | #define IDC_CLEAR 106 14 | #define IDC_GARBAGECOLLECT 107 15 | #define IDC_MEMMAP 108 16 | 17 | // Next default values for new objects 18 | // 19 | #ifdef APSTUDIO_INVOKED 20 | #ifndef APSTUDIO_READONLY_SYMBOLS 21 | #define _APS_NEXT_RESOURCE_VALUE 102 22 | #define _APS_NEXT_COMMAND_VALUE 40001 23 | #define _APS_NEXT_CONTROL_VALUE 1000 24 | #define _APS_NEXT_SYMED_VALUE 101 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /15-VMAlloc/VMAlloc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/15-VMAlloc/VMAlloc.ico -------------------------------------------------------------------------------- /15-VMAlloc/VMAlloc.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE DISCARDABLE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE DISCARDABLE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE DISCARDABLE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_VMALLOC DIALOG DISCARDABLE 15, 24, 224, 97 56 | STYLE WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "Virtual Memory Allocator" 58 | FONT 8, "MS Sans Serif" 59 | BEGIN 60 | LTEXT "Page size:",IDC_STATIC,4,6,34,8 61 | CONTROL "16 KB",IDC_PAGESIZE,"Static",SS_LEFTNOWORDWRAP | 62 | SS_NOPREFIX | WS_GROUP,50,6,20,8 63 | DEFPUSHBUTTON "&Reserve region (50, 2KB structures)",IDC_RESERVE,80,4, 64 | 140,14,WS_GROUP 65 | LTEXT "&Index (0 - 49):",IDC_INDEXTEXT,4,26,45,8 66 | EDITTEXT IDC_INDEX,56,24,16,12 67 | PUSHBUTTON "&Use",IDC_USE,80,24,32,14 68 | PUSHBUTTON "&Clear",IDC_CLEAR,116,24,32,14 69 | PUSHBUTTON "&Garbage collect",IDC_GARBAGECOLLECT,160,24,60,14 70 | GROUPBOX "Memory map",IDC_STATIC,4,42,216,52 71 | CONTROL "",IDC_MEMMAP,"Static",SS_BLACKRECT,8,58,208,16 72 | LTEXT "White: Free",IDC_STATIC,8,80,39,8 73 | CTEXT "Grey: Reserved",IDC_STATIC,82,80,52,8 74 | RTEXT "Black: Committed",IDC_STATIC,155,80,58,8 75 | END 76 | 77 | 78 | ///////////////////////////////////////////////////////////////////////////// 79 | // 80 | // Icon 81 | // 82 | 83 | // Icon with lowest ID value placed first to ensure application icon 84 | // remains consistent on all systems. 85 | IDI_VMALLOC ICON DISCARDABLE "VMAlloc.Ico" 86 | #endif // English (U.S.) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /16-Summation/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Summation.RC 4 | // 5 | #define IDD_SUMMATION 101 6 | #define IDI_SUMMATION 102 7 | #define IDC_SUMNUM 1000 8 | #define IDC_CALC 1001 9 | #define IDC_ANSWER 1002 10 | #define IDC_STATIC -1 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 103 17 | #define _APS_NEXT_COMMAND_VALUE 101 18 | #define _APS_NEXT_CONTROL_VALUE 1003 19 | #define _APS_NEXT_SYMED_VALUE 102 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /16-Summation/Summation.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/16-Summation/Summation.ico -------------------------------------------------------------------------------- /16-Summation/Summation.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Icon 29 | // 30 | 31 | // Icon with lowest ID value placed first to ensure application icon 32 | // remains consistent on all systems. 33 | IDI_SUMMATION ICON DISCARDABLE "Summation.ico" 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | // 37 | // Dialog 38 | // 39 | 40 | IDD_SUMMATION DIALOG DISCARDABLE 18, 18, 162, 41 41 | STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU 42 | CAPTION "Summation" 43 | FONT 8, "MS Sans Serif" 44 | BEGIN 45 | LTEXT "Calculate the sum of the numbers from 0 through &x, where x is: ", 46 | IDC_STATIC,4,4,112,20 47 | EDITTEXT IDC_SUMNUM,120,8,40,13,ES_AUTOHSCROLL 48 | DEFPUSHBUTTON "&Calculate",IDC_CALC,4,28,56,12 49 | LTEXT "Answer:",IDC_STATIC,68,30,30,8 50 | LTEXT "?",IDC_ANSWER,104,30,56,8 51 | END 52 | 53 | 54 | #ifdef APSTUDIO_INVOKED 55 | ///////////////////////////////////////////////////////////////////////////// 56 | // 57 | // TEXTINCLUDE 58 | // 59 | 60 | 1 TEXTINCLUDE DISCARDABLE 61 | BEGIN 62 | "Resource.h\0" 63 | END 64 | 65 | 2 TEXTINCLUDE DISCARDABLE 66 | BEGIN 67 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 68 | "#include ""windows.h""\r\n" 69 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 70 | "\0" 71 | END 72 | 73 | 3 TEXTINCLUDE DISCARDABLE 74 | BEGIN 75 | "\r\n" 76 | "\0" 77 | END 78 | 79 | #endif // APSTUDIO_INVOKED 80 | 81 | #endif // English (U.S.) resources 82 | ///////////////////////////////////////////////////////////////////////////// 83 | 84 | 85 | 86 | #ifndef APSTUDIO_INVOKED 87 | ///////////////////////////////////////////////////////////////////////////// 88 | // 89 | // Generated from the TEXTINCLUDE 3 resource. 90 | // 91 | 92 | 93 | ///////////////////////////////////////////////////////////////////////////// 94 | #endif // not APSTUDIO_INVOKED 95 | 96 | -------------------------------------------------------------------------------- /17-AppInst/AppInst.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: AppInst.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "Resource.h" 11 | 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | 16 | // The system-wide window message, unique to the application 17 | UINT g_uMsgAppInstCountUpdate = WM_APP+123; 18 | 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | 22 | 23 | // Tell the compiler to put this initialized variable in its own Shared 24 | // section so it is shared by all instances of this application. 25 | #pragma data_seg("Shared") 26 | volatile LONG g_lApplicationInstances = 0; 27 | #pragma data_seg() 28 | 29 | // Tell the linker to make the Shared section readable, writable, and shared. 30 | #pragma comment(linker, "/Section:Shared,RWS") 31 | 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | 35 | 36 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 37 | 38 | chSETDLGICONS(hWnd, IDI_APPINST); 39 | 40 | // Force the static control to be initialized correctly. 41 | PostMessage(HWND_BROADCAST, g_uMsgAppInstCountUpdate, 0, 0); 42 | return(TRUE); 43 | } 44 | 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | 48 | 49 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 50 | 51 | switch (id) { 52 | case IDCANCEL: 53 | EndDialog(hWnd, id); 54 | break; 55 | } 56 | } 57 | 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 63 | 64 | if (uMsg == g_uMsgAppInstCountUpdate) { 65 | SetDlgItemInt(hWnd, IDC_COUNT, g_lApplicationInstances, FALSE); 66 | } 67 | 68 | switch (uMsg) { 69 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 70 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 71 | } 72 | return(FALSE); 73 | } 74 | 75 | 76 | /////////////////////////////////////////////////////////////////////////////// 77 | 78 | 79 | int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR, int) { 80 | 81 | // Get the numeric value of the systemwide window message used to notify 82 | // all top-level windows when the module's usage count has changed. 83 | g_uMsgAppInstCountUpdate = 84 | RegisterWindowMessage(TEXT("MsgAppInstCountUpdate")); 85 | 86 | // There is another instance of this application running 87 | InterlockedExchangeAdd(&g_lApplicationInstances, 1); 88 | 89 | DialogBox(hInstExe, MAKEINTRESOURCE(IDD_APPINST), NULL, Dlg_Proc); 90 | 91 | // This instance of the application is terminating 92 | InterlockedExchangeAdd(&g_lApplicationInstances, -1); 93 | 94 | // Have all other instances update their display 95 | PostMessage(HWND_BROADCAST, g_uMsgAppInstCountUpdate, 0, 0); 96 | 97 | return(0); 98 | } 99 | 100 | 101 | //////////////////////////////// End of File ////////////////////////////////// 102 | -------------------------------------------------------------------------------- /17-AppInst/AppInst.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/17-AppInst/AppInst.ico -------------------------------------------------------------------------------- /17-AppInst/AppInst.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_APPINST DIALOGEX 0, 0, 161, 21 56 | STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "Application Instances" 58 | FONT 8, "MS Sans Serif", 0, 0, 0x0 59 | BEGIN 60 | LTEXT "Number of instances running:",IDC_STATIC,23,6,93,8,SS_NOPREFIX 61 | RTEXT "#",IDC_COUNT,123,6,16,12,SS_NOPREFIX 62 | END 63 | 64 | 65 | ///////////////////////////////////////////////////////////////////////////// 66 | // 67 | // Icon 68 | // 69 | 70 | // Icon with lowest ID value placed first to ensure application icon 71 | // remains consistent on all systems. 72 | IDI_APPINST ICON "AppInst.Ico" 73 | 74 | ///////////////////////////////////////////////////////////////////////////// 75 | // 76 | // DESIGNINFO 77 | // 78 | 79 | #ifdef APSTUDIO_INVOKED 80 | GUIDELINES DESIGNINFO 81 | BEGIN 82 | IDD_APPINST, DIALOG 83 | BEGIN 84 | RIGHTMARGIN, 97 85 | BOTTOMMARGIN, 20 86 | END 87 | END 88 | #endif // APSTUDIO_INVOKED 89 | 90 | #endif // English (U.S.) resources 91 | ///////////////////////////////////////////////////////////////////////////// 92 | 93 | 94 | 95 | #ifndef APSTUDIO_INVOKED 96 | ///////////////////////////////////////////////////////////////////////////// 97 | // 98 | // Generated from the TEXTINCLUDE 3 resource. 99 | // 100 | 101 | 102 | ///////////////////////////////////////////////////////////////////////////// 103 | #endif // not APSTUDIO_INVOKED 104 | 105 | -------------------------------------------------------------------------------- /17-AppInst/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by AppInst.RC 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_APPINST 1 7 | #define IDC_COUNT 100 8 | #define IDI_APPINST 101 9 | 10 | // Next default values for new objects 11 | // 12 | #ifdef APSTUDIO_INVOKED 13 | #ifndef APSTUDIO_READONLY_SYMBOLS 14 | #define _APS_NEXT_RESOURCE_VALUE 102 15 | #define _APS_NEXT_COMMAND_VALUE 40001 16 | #define _APS_NEXT_CONTROL_VALUE 1000 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /17-FileRev/FileRev.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/17-FileRev/FileRev.ico -------------------------------------------------------------------------------- /17-FileRev/FileRev.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_FILEREV ICON DISCARDABLE "FileRev.Ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "Resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | 59 | ///////////////////////////////////////////////////////////////////////////// 60 | // 61 | // Dialog 62 | // 63 | 64 | IDD_FILEREV DIALOG DISCARDABLE 15, 24, 216, 46 65 | STYLE WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 66 | CAPTION "File Reverse" 67 | FONT 8, "MS Sans Serif" 68 | BEGIN 69 | LTEXT "&Pathname:",IDC_STATIC,4,4,35,8 70 | EDITTEXT IDC_FILENAME,44,4,168,12,ES_AUTOHSCROLL 71 | PUSHBUTTON "&Browse...",IDC_FILESELECT,4,16,36,12,WS_GROUP 72 | DEFPUSHBUTTON "&Reverse file contents",IDC_REVERSE,4,32,80,12 73 | LTEXT "Type of characters in file:",IDC_STATIC,88,34,80,8 74 | LTEXT "(unknown)",IDC_TEXTTYPE,172,34,34,8 75 | END 76 | 77 | 78 | ///////////////////////////////////////////////////////////////////////////// 79 | // 80 | // DESIGNINFO 81 | // 82 | 83 | #ifdef APSTUDIO_INVOKED 84 | GUIDELINES DESIGNINFO DISCARDABLE 85 | BEGIN 86 | IDD_FILEREV, DIALOG 87 | BEGIN 88 | RIGHTMARGIN, 192 89 | BOTTOMMARGIN, 42 90 | END 91 | END 92 | #endif // APSTUDIO_INVOKED 93 | 94 | #endif // English (U.S.) resources 95 | ///////////////////////////////////////////////////////////////////////////// 96 | 97 | 98 | 99 | #ifndef APSTUDIO_INVOKED 100 | ///////////////////////////////////////////////////////////////////////////// 101 | // 102 | // Generated from the TEXTINCLUDE 3 resource. 103 | // 104 | 105 | 106 | ///////////////////////////////////////////////////////////////////////////// 107 | #endif // not APSTUDIO_INVOKED 108 | 109 | -------------------------------------------------------------------------------- /17-FileRev/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by FILEREV.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_FILEREV 1 7 | #define IDC_FILESELECT 101 8 | #define IDI_FILEREV 102 9 | #define IDC_FILENAME 1000 10 | #define IDC_REVERSE 1001 11 | #define IDC_TEXTTYPE 1002 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 103 18 | #define _APS_NEXT_COMMAND_VALUE 40001 19 | #define _APS_NEXT_CONTROL_VALUE 1003 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /17-MMFShare/MMFShare.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: MMFShare.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "Resource.h" 11 | 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | 15 | 16 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 17 | 18 | chSETDLGICONS(hWnd, IDI_MMFSHARE); 19 | 20 | // Initialize the edit control with some test data. 21 | Edit_SetText(GetDlgItem(hWnd, IDC_DATA), TEXT("Some test data")); 22 | 23 | // Disable the Close button because the file can't 24 | // be closed if it was never created or opened. 25 | Button_Enable(GetDlgItem(hWnd, IDC_CLOSEFILE), FALSE); 26 | return(TRUE); 27 | } 28 | 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | 33 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 34 | 35 | // Handle of the open memory-mapped file 36 | static HANDLE s_hFileMap = NULL; 37 | 38 | switch (id) { 39 | case IDCANCEL: 40 | EndDialog(hWnd, id); 41 | break; 42 | 43 | case IDC_CREATEFILE: 44 | if (codeNotify != BN_CLICKED) 45 | break; 46 | 47 | // Create a paging file-backed MMF to contain the edit control text. 48 | // The MMF is 4 KB at most and is named MMFSharedData. 49 | s_hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, 50 | PAGE_READWRITE, 0, 4 * 1024, TEXT("MMFSharedData")); 51 | 52 | if (s_hFileMap != NULL) { 53 | 54 | if (GetLastError() == ERROR_ALREADY_EXISTS) { 55 | chMB("Mapping already exists - not created."); 56 | CloseHandle(s_hFileMap); 57 | 58 | } else { 59 | 60 | // File mapping created successfully. 61 | 62 | // Map a view of the file into the address space. 63 | PVOID pView = MapViewOfFile(s_hFileMap, 64 | FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); 65 | 66 | if (pView != NULL) { 67 | // Put edit text into the MMF. 68 | Edit_GetText(GetDlgItem(hWnd, IDC_DATA), 69 | (PTSTR) pView, 4 * 1024); 70 | 71 | // Protect the MMF storage by unmapping it. 72 | UnmapViewOfFile(pView); 73 | 74 | // The user can't create another file right now. 75 | Button_Enable(hWndCtl, FALSE); 76 | 77 | // The user closed the file. 78 | Button_Enable(GetDlgItem(hWnd, IDC_CLOSEFILE), TRUE); 79 | 80 | } else { 81 | chMB("Can't map view of file."); 82 | } 83 | } 84 | 85 | } else { 86 | chMB("Can't create file mapping."); 87 | } 88 | break; 89 | 90 | case IDC_CLOSEFILE: 91 | if (codeNotify != BN_CLICKED) 92 | break; 93 | 94 | if (CloseHandle(s_hFileMap)) { 95 | // User closed the file, fix up the buttons. 96 | Button_Enable(GetDlgItem(hWnd, IDC_CREATEFILE), TRUE); 97 | Button_Enable(hWndCtl, FALSE); 98 | } 99 | break; 100 | 101 | case IDC_OPENFILE: 102 | if (codeNotify != BN_CLICKED) 103 | break; 104 | 105 | // See if a memory-mapped file named MMFSharedData already exists. 106 | HANDLE hFileMapT = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, 107 | FALSE, TEXT("MMFSharedData")); 108 | 109 | if (hFileMapT != NULL) { 110 | // The MMF does exist, map it into the process's address space. 111 | PVOID pView = MapViewOfFile(hFileMapT, 112 | FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); 113 | 114 | if (pView != NULL) { 115 | 116 | // Put the contents of the MMF into the edit control. 117 | Edit_SetText(GetDlgItem(hWnd, IDC_DATA), (PTSTR) pView); 118 | UnmapViewOfFile(pView); 119 | } else { 120 | chMB("Can't map view."); 121 | } 122 | 123 | CloseHandle(hFileMapT); 124 | 125 | } else { 126 | chMB("Can't open mapping."); 127 | } 128 | break; 129 | } 130 | } 131 | 132 | 133 | /////////////////////////////////////////////////////////////////////////////// 134 | 135 | 136 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 137 | 138 | switch (uMsg) { 139 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 140 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 141 | } 142 | return(FALSE); 143 | } 144 | 145 | 146 | /////////////////////////////////////////////////////////////////////////////// 147 | 148 | 149 | int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR, int) { 150 | 151 | DialogBox(hInstExe, MAKEINTRESOURCE(IDD_MMFSHARE), NULL, Dlg_Proc); 152 | return(0); 153 | } 154 | 155 | 156 | //////////////////////////////// End of File ////////////////////////////////// 157 | -------------------------------------------------------------------------------- /17-MMFShare/MMFShare.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/17-MMFShare/MMFShare.ico -------------------------------------------------------------------------------- /17-MMFShare/MMFShare.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_MMFSHARE DIALOG DISCARDABLE 38, 36, 186, 61 30 | STYLE WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 31 | CAPTION "Memory-Mapped File Sharing" 32 | FONT 8, "MS Sans Serif" 33 | BEGIN 34 | PUSHBUTTON "&Create mapping of Data",IDC_CREATEFILE,4,4,84,14, 35 | WS_GROUP 36 | PUSHBUTTON "&Close mapping of Data",IDC_CLOSEFILE,96,4,84,14 37 | LTEXT "&Data:",IDC_STATIC,4,26,18,8 38 | EDITTEXT IDC_DATA,28,24,153,12 39 | PUSHBUTTON "&Open mapping and get Data",IDC_OPENFILE,40,44,104,14, 40 | WS_GROUP 41 | END 42 | 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // 46 | // Icon 47 | // 48 | 49 | // Icon with lowest ID value placed first to ensure application icon 50 | // remains consistent on all systems. 51 | IDI_MMFSHARE ICON DISCARDABLE "MMFShare.Ico" 52 | 53 | #ifdef APSTUDIO_INVOKED 54 | ///////////////////////////////////////////////////////////////////////////// 55 | // 56 | // TEXTINCLUDE 57 | // 58 | 59 | 1 TEXTINCLUDE DISCARDABLE 60 | BEGIN 61 | "Resource.h\0" 62 | END 63 | 64 | 2 TEXTINCLUDE DISCARDABLE 65 | BEGIN 66 | "#include ""Windows.h""\r\n" 67 | "\0" 68 | END 69 | 70 | 3 TEXTINCLUDE DISCARDABLE 71 | BEGIN 72 | "\r\n" 73 | "\0" 74 | END 75 | 76 | #endif // APSTUDIO_INVOKED 77 | 78 | #endif // English (U.S.) resources 79 | ///////////////////////////////////////////////////////////////////////////// 80 | 81 | 82 | 83 | #ifndef APSTUDIO_INVOKED 84 | ///////////////////////////////////////////////////////////////////////////// 85 | // 86 | // Generated from the TEXTINCLUDE 3 resource. 87 | // 88 | 89 | 90 | ///////////////////////////////////////////////////////////////////////////// 91 | #endif // not APSTUDIO_INVOKED 92 | 93 | -------------------------------------------------------------------------------- /17-MMFShare/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by MMFSHARE.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_MMFSHARE 1 7 | #define IDC_DATA 100 8 | #define IDC_CREATEFILE 101 9 | #define IDC_OPENFILE 102 10 | #define IDI_MMFSHARE 102 11 | #define IDC_CLOSEFILE 103 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 103 18 | #define _APS_NEXT_COMMAND_VALUE 40001 19 | #define _APS_NEXT_CONTROL_VALUE 1000 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /17-MMFSparse/MMFSparse.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/17-MMFSparse/MMFSparse.ico -------------------------------------------------------------------------------- /17-MMFSparse/MMFSparse.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_MMFSPARSE DIALOGEX 15, 24, 172, 201 56 | STYLE DS_SETFONT | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "MMF Sparse" 58 | FONT 8, "MS Sans Serif", 0, 0, 0x0 59 | BEGIN 60 | DEFPUSHBUTTON "&Create a 1MB (1024 KB) Sparse MMF",IDC_CREATEMMF,4,4,164,14,WS_GROUP 61 | LTEXT "&Offset (0 - 1023KB):",IDC_STATIC,4,24,63,8 62 | EDITTEXT IDC_OFFSET,72,22,44,12 63 | PUSHBUTTON "&Read byte",IDC_READBYTE,122,20,46,14 64 | LTEXT "&Byte (0-255):",IDC_STATIC,4,36,41,8 65 | EDITTEXT IDC_BYTE,72,36,44,12,ES_UPPERCASE | ES_NUMBER 66 | PUSHBUTTON "&Write byte",IDC_WRITEBYTE,122,36,46,14 67 | PUSHBUTTON "&Free all allocated regions",IDC_FREEALLOCATEDREGIONS,76,52,92,14 68 | LTEXT "&Allocated Ranges:",IDC_STATIC,4,68,59,8 69 | EDITTEXT IDC_FILESTATUS,4,80,164,116,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL 70 | END 71 | 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | // 75 | // Icon 76 | // 77 | 78 | // Icon with lowest ID value placed first to ensure application icon 79 | // remains consistent on all systems. 80 | IDI_MMFSPARSE ICON "MMFSparse.Ico" 81 | 82 | ///////////////////////////////////////////////////////////////////////////// 83 | // 84 | // DESIGNINFO 85 | // 86 | 87 | #ifdef APSTUDIO_INVOKED 88 | GUIDELINES DESIGNINFO 89 | BEGIN 90 | IDD_MMFSPARSE, DIALOG 91 | BEGIN 92 | BOTTOMMARGIN, 198 93 | END 94 | END 95 | #endif // APSTUDIO_INVOKED 96 | 97 | #endif // English (U.S.) resources 98 | ///////////////////////////////////////////////////////////////////////////// 99 | 100 | 101 | 102 | #ifndef APSTUDIO_INVOKED 103 | ///////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Generated from the TEXTINCLUDE 3 resource. 106 | // 107 | 108 | 109 | ///////////////////////////////////////////////////////////////////////////// 110 | #endif // not APSTUDIO_INVOKED 111 | 112 | -------------------------------------------------------------------------------- /17-MMFSparse/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by MMFSparse.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_MMFSPARSE 1 7 | #define IDC_CREATEMMF 101 8 | #define IDI_MMFSPARSE 102 9 | #define IDC_OFFSET 103 10 | #define IDC_WRITEBYTE 105 11 | #define IDC_READBYTE 106 12 | #define IDC_BYTE 109 13 | #define IDC_FILESTATUS 1000 14 | #define IDC_FREEALLOCATEDREGIONS 1002 15 | 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | #define _APS_NEXT_RESOURCE_VALUE 103 21 | #define _APS_NEXT_COMMAND_VALUE 40001 22 | #define _APS_NEXT_CONTROL_VALUE 1003 23 | #define _APS_NEXT_SYMED_VALUE 101 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /17-MMFSparse/SparseStream.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: SparseStream.h 3 | Notices: Copyright (c) 2007 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | 14 | #pragma once 15 | 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | 20 | class CSparseStream { 21 | public: 22 | static BOOL DoesFileSystemSupportSparseStreams(PCTSTR pszVolume); 23 | static BOOL DoesFileContainAnySparseStreams(PCTSTR pszPathname); 24 | 25 | public: 26 | CSparseStream(HANDLE hStream = INVALID_HANDLE_VALUE) { 27 | Initialize(hStream); 28 | } 29 | 30 | virtual ~CSparseStream() { } 31 | 32 | void Initialize(HANDLE hStream = INVALID_HANDLE_VALUE) { 33 | m_hStream = hStream; 34 | } 35 | 36 | public: 37 | operator HANDLE() const { return(m_hStream); } 38 | 39 | public: 40 | BOOL IsStreamSparse() const; 41 | BOOL MakeSparse(); 42 | BOOL DecommitPortionOfStream( 43 | __int64 qwFileOffsetStart, __int64 qwFileOffsetEnd); 44 | 45 | FILE_ALLOCATED_RANGE_BUFFER* QueryAllocatedRanges(PDWORD pdwNumEntries); 46 | BOOL FreeAllocatedRanges(FILE_ALLOCATED_RANGE_BUFFER* pfarb); 47 | 48 | private: 49 | HANDLE m_hStream; 50 | 51 | private: 52 | static BOOL AreFlagsSet(DWORD fdwFlagBits, DWORD fFlagsToCheck) { 53 | return((fdwFlagBits & fFlagsToCheck) == fFlagsToCheck); 54 | } 55 | }; 56 | 57 | 58 | /////////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | inline BOOL CSparseStream::DoesFileSystemSupportSparseStreams( 62 | PCTSTR pszVolume) { 63 | 64 | DWORD dwFileSystemFlags = 0; 65 | BOOL bOk = GetVolumeInformation(pszVolume, NULL, 0, NULL, NULL, 66 | &dwFileSystemFlags, NULL, 0); 67 | bOk = bOk && AreFlagsSet(dwFileSystemFlags, FILE_SUPPORTS_SPARSE_FILES); 68 | return(bOk); 69 | } 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////// 73 | 74 | 75 | inline BOOL CSparseStream::IsStreamSparse() const { 76 | 77 | BY_HANDLE_FILE_INFORMATION bhfi; 78 | GetFileInformationByHandle(m_hStream, &bhfi); 79 | return(AreFlagsSet(bhfi.dwFileAttributes, FILE_ATTRIBUTE_SPARSE_FILE)); 80 | } 81 | 82 | 83 | /////////////////////////////////////////////////////////////////////////////// 84 | 85 | 86 | inline BOOL CSparseStream::MakeSparse() { 87 | 88 | DWORD dw; 89 | return(DeviceIoControl(m_hStream, FSCTL_SET_SPARSE, 90 | NULL, 0, NULL, 0, &dw, NULL)); 91 | } 92 | 93 | 94 | /////////////////////////////////////////////////////////////////////////////// 95 | 96 | 97 | inline BOOL CSparseStream::DecommitPortionOfStream( 98 | __int64 qwOffsetStart, __int64 qwOffsetEnd) { 99 | 100 | // NOTE: This function does not work if this file is memory-mapped. 101 | DWORD dw; 102 | FILE_ZERO_DATA_INFORMATION fzdi; 103 | fzdi.FileOffset.QuadPart = qwOffsetStart; 104 | fzdi.BeyondFinalZero.QuadPart = qwOffsetEnd + 1; 105 | return(DeviceIoControl(m_hStream, FSCTL_SET_ZERO_DATA, (PVOID) &fzdi, 106 | sizeof(fzdi), NULL, 0, &dw, NULL)); 107 | } 108 | 109 | 110 | /////////////////////////////////////////////////////////////////////////////// 111 | 112 | 113 | inline BOOL CSparseStream::DoesFileContainAnySparseStreams( 114 | PCTSTR pszPathname) { 115 | 116 | DWORD dw = GetFileAttributes(pszPathname); 117 | return((dw == 0xfffffff) 118 | ? FALSE : AreFlagsSet(dw, FILE_ATTRIBUTE_SPARSE_FILE)); 119 | } 120 | 121 | 122 | /////////////////////////////////////////////////////////////////////////////// 123 | 124 | 125 | inline FILE_ALLOCATED_RANGE_BUFFER* CSparseStream::QueryAllocatedRanges( 126 | PDWORD pdwNumEntries) { 127 | 128 | FILE_ALLOCATED_RANGE_BUFFER farb; 129 | farb.FileOffset.QuadPart = 0; 130 | farb.Length.LowPart = 131 | GetFileSize(m_hStream, (PDWORD) &farb.Length.HighPart); 132 | 133 | // There is no way to determine the correct memory block size prior to 134 | // attempting to collect this data, so I just picked 100 * sizeof(*pfarb) 135 | DWORD cb = 100 * sizeof(farb); 136 | FILE_ALLOCATED_RANGE_BUFFER* pfarb = (FILE_ALLOCATED_RANGE_BUFFER*) 137 | HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb); 138 | 139 | DeviceIoControl(m_hStream, FSCTL_QUERY_ALLOCATED_RANGES, 140 | &farb, sizeof(farb), pfarb, cb, &cb, NULL); 141 | *pdwNumEntries = cb / sizeof(*pfarb); 142 | return(pfarb); 143 | } 144 | 145 | 146 | /////////////////////////////////////////////////////////////////////////////// 147 | 148 | 149 | inline BOOL CSparseStream::FreeAllocatedRanges( 150 | FILE_ALLOCATED_RANGE_BUFFER* pfarb) { 151 | 152 | // Free the queue entry's allocated memory 153 | return(HeapFree(GetProcessHeap(), 0, pfarb)); 154 | } 155 | 156 | 157 | ///////////////////////////////// End Of File ///////////////////////////////// 158 | -------------------------------------------------------------------------------- /20-DelayLoadApp/DelayLoadApp.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/20-DelayLoadApp/DelayLoadApp.ico -------------------------------------------------------------------------------- /20-DelayLoadApp/DelayLoadApp.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_DELAYLOADAPP ICON DISCARDABLE "DelayLoadApp.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | #endif // English (U.S.) resources 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | 63 | #ifndef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Generated from the TEXTINCLUDE 3 resource. 67 | // 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | #endif // not APSTUDIO_INVOKED 72 | 73 | -------------------------------------------------------------------------------- /20-DelayLoadApp/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by DelayLoadApp.rc 4 | // 5 | #define IDI_DELAYLOADAPP 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /20-DelayLoadLib/DelayLoadLib.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: DelayLoadLib.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | #define DELAYLOADLIBAPI extern "C" __declspec(dllexport) 16 | #include "DelayLoadLib.h" 17 | 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | 22 | int fnLib() { 23 | 24 | return(321); 25 | } 26 | 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | 30 | 31 | int fnLib2() { 32 | 33 | return(123); 34 | } 35 | 36 | 37 | //////////////////////////////// End of File ////////////////////////////////// 38 | -------------------------------------------------------------------------------- /20-DelayLoadLib/DelayLoadLib.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: DelayLoadLib.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #ifndef DELAYLOADLIBAPI 8 | #define DELAYLOADLIBAPI extern "C" __declspec(dllimport) 9 | #endif 10 | 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | DELAYLOADLIBAPI int fnLib(); 16 | DELAYLOADLIBAPI int fnLib2(); 17 | 18 | 19 | //////////////////////////////// End of File ////////////////////////////////// 20 | -------------------------------------------------------------------------------- /22-DIPS/DIPS.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: DIPS.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "Resource.h" 11 | #include "..\22-DIPSLib\DIPSLib.h" 12 | 13 | 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | 17 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 18 | 19 | chSETDLGICONS(hWnd, IDI_DIPS); 20 | return(TRUE); 21 | } 22 | 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | 26 | 27 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 28 | 29 | switch (id) { 30 | case IDC_SAVE: 31 | case IDC_RESTORE: 32 | case IDCANCEL: 33 | EndDialog(hWnd, id); 34 | break; 35 | } 36 | } 37 | 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | 42 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 43 | 44 | switch (uMsg) { 45 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 46 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 47 | } 48 | 49 | return(FALSE); 50 | } 51 | 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | 55 | 56 | int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int) { 57 | 58 | // Convert command-line character to uppercase. 59 | CharUpperBuff(pszCmdLine, 1); 60 | TCHAR cWhatToDo = pszCmdLine[0]; 61 | 62 | if ((cWhatToDo != TEXT('S')) && (cWhatToDo != TEXT('R'))) { 63 | 64 | // An invalid command-line argument; prompt the user. 65 | cWhatToDo = 0; 66 | } 67 | 68 | if (cWhatToDo == 0) { 69 | // No command-line argument was used to tell us what to 70 | // do; show usage dialog box and prompt the user. 71 | switch (DialogBox(hInstExe, MAKEINTRESOURCE(IDD_DIPS), NULL, Dlg_Proc)) { 72 | case IDC_SAVE: 73 | cWhatToDo = TEXT('S'); 74 | break; 75 | 76 | case IDC_RESTORE: 77 | cWhatToDo = TEXT('R'); 78 | break; 79 | } 80 | } 81 | 82 | if (cWhatToDo == 0) { 83 | // The user doesn't want to do anything. 84 | return(0); 85 | } 86 | 87 | // The Desktop ListView window is the grandchild of the ProgMan window. 88 | HWND hWndLV = GetFirstChild(GetFirstChild( 89 | FindWindow(TEXT("ProgMan"), NULL))); 90 | chASSERT(IsWindow(hWndLV)); 91 | 92 | // Set hook that injects our DLL into the Explorer's address space. After 93 | // setting the hook, the DIPS hidden modeless dialog box is created. We 94 | // send messages to this window to tell it what we want it to do. 95 | chVERIFY(SetDIPSHook(GetWindowThreadProcessId(hWndLV, NULL))); 96 | 97 | // Wait for the DIPS server window to be created. 98 | MSG msg; 99 | GetMessage(&msg, NULL, 0, 0); 100 | 101 | // Find the handle of the hidden dialog box window. 102 | HWND hWndDIPS = FindWindow(NULL, TEXT("Wintellect DIPS")); 103 | 104 | // Make sure that the window was created. 105 | chASSERT(IsWindow(hWndDIPS)); 106 | 107 | // Tell the DIPS window which ListView window to manipulate 108 | // and whether the items should be saved or restored. 109 | BOOL bSave = (cWhatToDo == TEXT('S')); 110 | SendMessage(hWndDIPS, WM_APP, (WPARAM) hWndLV, bSave); 111 | 112 | // Tell the DIPS window to destroy itself. Use SendMessage 113 | // instead of PostMessage so that we know the window is 114 | // destroyed before the hook is removed. 115 | SendMessage(hWndDIPS, WM_CLOSE, 0, 0); 116 | 117 | // Make sure that the window was destroyed. 118 | chASSERT(!IsWindow(hWndDIPS)); 119 | 120 | // Unhook the DLL, removing the DIPS dialog box procedure 121 | // from the Explorer's address space. 122 | SetDIPSHook(0); 123 | 124 | return(0); 125 | } 126 | 127 | 128 | //////////////////////////////// End of File ////////////////////////////////// 129 | -------------------------------------------------------------------------------- /22-DIPS/DIPS.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/22-DIPS/DIPS.ico -------------------------------------------------------------------------------- /22-DIPS/DIPS.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_DIPS ICON "DIPS.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | 59 | ///////////////////////////////////////////////////////////////////////////// 60 | // 61 | // Dialog 62 | // 63 | 64 | IDD_DIPS DIALOGEX 0, 0, 208, 95 65 | STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU 66 | CAPTION "Desktop Item Position Saver Utility" 67 | FONT 8, "MS Sans Serif", 0, 0, 0x1 68 | BEGIN 69 | CTEXT "DIPS: Desktop Item Position Saver Utility\nCopyright (c) 2008 by Jeffrey Richter && Christophe Nasarre.",IDC_STATIC,4,4,200,20,SS_SUNKEN,WS_EX_DLGMODALFRAME | WS_EX_STATICEDGE 70 | LTEXT "This utility saves/restores the position of items on the desktop.\n\nTo save the desktop item positions: DIPS S\nTo restore the desktop item positions: DIPS R",IDC_STATIC,4,32,200,36 71 | DEFPUSHBUTTON "&Save",IDC_SAVE,4,76,50,14 72 | PUSHBUTTON "&Restore",IDC_RESTORE,79,76,50,14 73 | PUSHBUTTON "Cancel",IDCANCEL,154,76,50,14 74 | END 75 | 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // DESIGNINFO 80 | // 81 | 82 | #ifdef APSTUDIO_INVOKED 83 | GUIDELINES DESIGNINFO 84 | BEGIN 85 | IDD_DIPS, DIALOG 86 | BEGIN 87 | LEFTMARGIN, 7 88 | RIGHTMARGIN, 201 89 | TOPMARGIN, 7 90 | BOTTOMMARGIN, 88 91 | END 92 | END 93 | #endif // APSTUDIO_INVOKED 94 | 95 | #endif // English (U.S.) resources 96 | ///////////////////////////////////////////////////////////////////////////// 97 | 98 | 99 | 100 | #ifndef APSTUDIO_INVOKED 101 | ///////////////////////////////////////////////////////////////////////////// 102 | // 103 | // Generated from the TEXTINCLUDE 3 resource. 104 | // 105 | 106 | 107 | ///////////////////////////////////////////////////////////////////////////// 108 | #endif // not APSTUDIO_INVOKED 109 | 110 | -------------------------------------------------------------------------------- /22-DIPS/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by DIPS.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDC_RESTORE 3 7 | #define IDI_DIPS 101 8 | #define IDD_DIPS 102 9 | #define IDC_SAVE 1000 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 103 16 | #define _APS_NEXT_COMMAND_VALUE 40001 17 | #define _APS_NEXT_CONTROL_VALUE 1001 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /22-DIPSLib/DIPSLib.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: DIPSLib.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #if !defined(DIPSLIBAPI) 8 | #define DIPSLIBAPI __declspec(dllimport) 9 | #endif 10 | 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | // External function prototypes 16 | DIPSLIBAPI BOOL WINAPI SetDIPSHook(DWORD dwThreadId); 17 | 18 | 19 | //////////////////////////////// End of File ////////////////////////////////// 20 | -------------------------------------------------------------------------------- /22-DIPSLib/DIPSLib.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_DIPS DIALOG DISCARDABLE 0, 0, 132, 13 30 | STYLE WS_CAPTION 31 | CAPTION "Wintellect DIPS" 32 | FONT 8, "MS Sans Serif" 33 | BEGIN 34 | END 35 | 36 | 37 | #ifdef APSTUDIO_INVOKED 38 | ///////////////////////////////////////////////////////////////////////////// 39 | // 40 | // TEXTINCLUDE 41 | // 42 | 43 | 1 TEXTINCLUDE DISCARDABLE 44 | BEGIN 45 | "resource.h\0" 46 | END 47 | 48 | 2 TEXTINCLUDE DISCARDABLE 49 | BEGIN 50 | "#include ""Windows.h""\r\n" 51 | "\0" 52 | END 53 | 54 | 3 TEXTINCLUDE DISCARDABLE 55 | BEGIN 56 | "\r\n" 57 | "\0" 58 | END 59 | 60 | #endif // APSTUDIO_INVOKED 61 | 62 | #endif // English (U.S.) resources 63 | ///////////////////////////////////////////////////////////////////////////// 64 | 65 | 66 | 67 | #ifndef APSTUDIO_INVOKED 68 | ///////////////////////////////////////////////////////////////////////////// 69 | // 70 | // Generated from the TEXTINCLUDE 3 resource. 71 | // 72 | 73 | 74 | ///////////////////////////////////////////////////////////////////////////// 75 | #endif // not APSTUDIO_INVOKED 76 | 77 | -------------------------------------------------------------------------------- /22-DIPSLib/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by DIPSLib.rc 4 | // 5 | #define IDD_DIPS 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /22-ImgWalk/ImgWalk.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: ImgWalk.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | 14 | BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, PVOID fImpLoad) { 15 | 16 | if (fdwReason == DLL_PROCESS_ATTACH) { 17 | char szBuf[MAX_PATH * 100] = { 0 }; 18 | 19 | PBYTE pb = NULL; 20 | MEMORY_BASIC_INFORMATION mbi; 21 | while (VirtualQuery(pb, &mbi, sizeof(mbi)) == sizeof(mbi)) { 22 | 23 | int nLen; 24 | char szModName[MAX_PATH]; 25 | 26 | if (mbi.State == MEM_FREE) 27 | mbi.AllocationBase = mbi.BaseAddress; 28 | 29 | if ((mbi.AllocationBase == hInstDll) || 30 | (mbi.AllocationBase != mbi.BaseAddress) || 31 | (mbi.AllocationBase == NULL)) { 32 | // Do not add the module name to the list 33 | // if any of the following is true: 34 | // 1. If this region contains this DLL 35 | // 2. If this block is NOT the beginning of a region 36 | // 3. If the address is NULL 37 | nLen = 0; 38 | } else { 39 | nLen = GetModuleFileNameA((HINSTANCE) mbi.AllocationBase, 40 | szModName, _countof(szModName)); 41 | } 42 | 43 | if (nLen > 0) { 44 | wsprintfA(strchr(szBuf, 0), "\n%p-%s", 45 | mbi.AllocationBase, szModName); 46 | } 47 | 48 | pb += mbi.RegionSize; 49 | } 50 | 51 | // NOTE: Normally, you should not display a message box in DllMain 52 | // due to the loader lock described in Chapter 20. However, to keep 53 | // this sample application simple, I am violating this rule. 54 | chMB(&szBuf[1]); 55 | } 56 | 57 | return(TRUE); 58 | } 59 | 60 | 61 | //////////////////////////////// End of File ////////////////////////////////// 62 | -------------------------------------------------------------------------------- /22-InjLib/InjLib.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/22-InjLib/InjLib.ico -------------------------------------------------------------------------------- /22-InjLib/InjLib.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_INJLIB ICON DISCARDABLE "InjLib.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | 59 | ///////////////////////////////////////////////////////////////////////////// 60 | // 61 | // Dialog 62 | // 63 | 64 | IDD_INJLIB DIALOG DISCARDABLE 15, 24, 158, 24 65 | STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | 66 | WS_SYSMENU 67 | CAPTION "Inject Library Tester" 68 | FONT 8, "MS Sans Serif" 69 | BEGIN 70 | LTEXT "&Process Id (decimal):",-1,4,6,69,8 71 | EDITTEXT IDC_PROCESSID,78,4,36,12,ES_AUTOHSCROLL 72 | DEFPUSHBUTTON "&Inject",IDC_INJECT,120,4,36,12,WS_GROUP 73 | END 74 | 75 | 76 | ///////////////////////////////////////////////////////////////////////////// 77 | // 78 | // DESIGNINFO 79 | // 80 | 81 | #ifdef APSTUDIO_INVOKED 82 | GUIDELINES DESIGNINFO DISCARDABLE 83 | BEGIN 84 | IDD_INJLIB, DIALOG 85 | BEGIN 86 | RIGHTMARGIN, 134 87 | BOTTOMMARGIN, 20 88 | END 89 | END 90 | #endif // APSTUDIO_INVOKED 91 | 92 | #endif // English (U.S.) resources 93 | ///////////////////////////////////////////////////////////////////////////// 94 | 95 | 96 | 97 | #ifndef APSTUDIO_INVOKED 98 | ///////////////////////////////////////////////////////////////////////////// 99 | // 100 | // Generated from the TEXTINCLUDE 3 resource. 101 | // 102 | 103 | 104 | ///////////////////////////////////////////////////////////////////////////// 105 | #endif // not APSTUDIO_INVOKED 106 | 107 | -------------------------------------------------------------------------------- /22-InjLib/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by InjLib.RC 4 | // 5 | #define IDD_INJLIB 1 6 | #define IDC_INJECT 100 7 | #define IDC_PROCESSID 101 8 | #define IDI_INJLIB 101 9 | 10 | // Next default values for new objects 11 | // 12 | #ifdef APSTUDIO_INVOKED 13 | #ifndef APSTUDIO_READONLY_SYMBOLS 14 | #define _APS_NEXT_RESOURCE_VALUE 102 15 | #define _APS_NEXT_COMMAND_VALUE 40001 16 | #define _APS_NEXT_CONTROL_VALUE 1000 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /22-LastMsgBoxInfo/LastMsgBoxInfo.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: LastMsgBoxInfo.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 8 | #include 9 | #include 10 | #include "Resource.h" 11 | #include "..\22-LastMsgBoxInfoLib\LastMsgBoxInfoLib.h" 12 | 13 | 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | 17 | BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) { 18 | 19 | chSETDLGICONS(hWnd, IDI_LASTMSGBOXINFO); 20 | SetDlgItemText(hWnd, IDC_INFO, 21 | TEXT("Waiting for a Message Box to be dismissed")); 22 | return(TRUE); 23 | } 24 | 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | 28 | 29 | void Dlg_OnSize(HWND hWnd, UINT state, int cx, int cy) { 30 | 31 | SetWindowPos(GetDlgItem(hWnd, IDC_INFO), NULL, 32 | 0, 0, cx, cy, SWP_NOZORDER); 33 | } 34 | 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | 38 | 39 | void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { 40 | 41 | switch (id) { 42 | case IDCANCEL: 43 | EndDialog(hWnd, id); 44 | break; 45 | } 46 | } 47 | 48 | 49 | /////////////////////////////////////////////////////////////////////////////// 50 | 51 | 52 | BOOL Dlg_OnCopyData(HWND hWnd, HWND hWndFrom, PCOPYDATASTRUCT pcds) { 53 | 54 | // Some hooked process sent us some message box info, display it 55 | SetDlgItemTextW(hWnd, IDC_INFO, (PCWSTR) pcds->lpData); 56 | return(TRUE); 57 | } 58 | 59 | 60 | /////////////////////////////////////////////////////////////////////////////// 61 | 62 | 63 | INT_PTR WINAPI Dlg_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 64 | 65 | switch (uMsg) { 66 | chHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Dlg_OnInitDialog); 67 | chHANDLE_DLGMSG(hWnd, WM_SIZE, Dlg_OnSize); 68 | chHANDLE_DLGMSG(hWnd, WM_COMMAND, Dlg_OnCommand); 69 | chHANDLE_DLGMSG(hWnd, WM_COPYDATA, Dlg_OnCopyData); 70 | } 71 | return(FALSE); 72 | } 73 | 74 | 75 | /////////////////////////////////////////////////////////////////////////////// 76 | 77 | 78 | int WINAPI _tWinMain(HINSTANCE hInstExe, HINSTANCE, PTSTR pszCmdLine, int) { 79 | 80 | DWORD dwThreadId = 0; 81 | LastMsgBoxInfo_HookAllApps(TRUE, dwThreadId); 82 | DialogBox(hInstExe, MAKEINTRESOURCE(IDD_LASTMSGBOXINFO), NULL, Dlg_Proc); 83 | LastMsgBoxInfo_HookAllApps(FALSE, 0); 84 | return(0); 85 | } 86 | 87 | 88 | //////////////////////////////// End of File ////////////////////////////////// 89 | -------------------------------------------------------------------------------- /22-LastMsgBoxInfo/LastMsgBoxInfo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/22-LastMsgBoxInfo/LastMsgBoxInfo.ico -------------------------------------------------------------------------------- /22-LastMsgBoxInfo/LastMsgBoxInfo.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | IDD_LASTMSGBOXINFO DIALOG DISCARDABLE 0, 0, 379, 55 30 | STYLE DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_CAPTION | 31 | WS_SYSMENU | WS_THICKFRAME 32 | CAPTION "Last MessageBox Info" 33 | FONT 8, "MS Sans Serif" 34 | BEGIN 35 | EDITTEXT IDC_INFO,0,0,376,52,ES_MULTILINE | ES_AUTOVSCROLL | 36 | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL 37 | END 38 | 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // 42 | // DESIGNINFO 43 | // 44 | 45 | #ifdef APSTUDIO_INVOKED 46 | GUIDELINES DESIGNINFO DISCARDABLE 47 | BEGIN 48 | IDD_LASTMSGBOXINFO, DIALOG 49 | BEGIN 50 | LEFTMARGIN, 7 51 | RIGHTMARGIN, 372 52 | TOPMARGIN, 7 53 | BOTTOMMARGIN, 48 54 | END 55 | END 56 | #endif // APSTUDIO_INVOKED 57 | 58 | 59 | #ifdef APSTUDIO_INVOKED 60 | ///////////////////////////////////////////////////////////////////////////// 61 | // 62 | // TEXTINCLUDE 63 | // 64 | 65 | 1 TEXTINCLUDE DISCARDABLE 66 | BEGIN 67 | "resource.h\0" 68 | END 69 | 70 | 2 TEXTINCLUDE DISCARDABLE 71 | BEGIN 72 | "#include ""Windows.h""\r\n" 73 | "\0" 74 | END 75 | 76 | 3 TEXTINCLUDE DISCARDABLE 77 | BEGIN 78 | "\r\n" 79 | "\0" 80 | END 81 | 82 | #endif // APSTUDIO_INVOKED 83 | 84 | 85 | ///////////////////////////////////////////////////////////////////////////// 86 | // 87 | // Icon 88 | // 89 | 90 | // Icon with lowest ID value placed first to ensure application icon 91 | // remains consistent on all systems. 92 | IDI_LASTMSGBOXINFO ICON DISCARDABLE "LastMsgBoxInfo.ico" 93 | #endif // English (U.S.) resources 94 | ///////////////////////////////////////////////////////////////////////////// 95 | 96 | 97 | 98 | #ifndef APSTUDIO_INVOKED 99 | ///////////////////////////////////////////////////////////////////////////// 100 | // 101 | // Generated from the TEXTINCLUDE 3 resource. 102 | // 103 | 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | #endif // not APSTUDIO_INVOKED 107 | 108 | -------------------------------------------------------------------------------- /22-LastMsgBoxInfo/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by LastMsgBoxInfo.rc 4 | // 5 | #define IDD_LASTMSGBOXINFO 101 6 | #define IDI_LASTMSGBOXINFO 102 7 | #define IDC_INFO 1001 8 | 9 | // Next default values for new objects 10 | // 11 | #ifdef APSTUDIO_INVOKED 12 | #ifndef APSTUDIO_READONLY_SYMBOLS 13 | #define _APS_NEXT_RESOURCE_VALUE 103 14 | #define _APS_NEXT_COMMAND_VALUE 40001 15 | #define _APS_NEXT_CONTROL_VALUE 1002 16 | #define _APS_NEXT_SYMED_VALUE 101 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /22-LastMsgBoxInfoLib/APIHook.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: APIHook.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #pragma once 8 | 9 | 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | 13 | class CAPIHook { 14 | public: 15 | // Hook a function in all modules 16 | CAPIHook(PSTR pszCalleeModName, PSTR pszFuncName, PROC pfnHook); 17 | 18 | // Unhook a function from all modules 19 | ~CAPIHook(); 20 | 21 | // Returns the original address of the hooked function 22 | operator PROC() { return(m_pfnOrig); } 23 | 24 | // Hook module w/CAPIHook implementation? 25 | // I have to make it static because I need to use it 26 | // in ReplaceIATEntryInAllMods 27 | static BOOL ExcludeAPIHookMod; 28 | 29 | 30 | public: 31 | // Calls the real GetProcAddress 32 | static FARPROC WINAPI GetProcAddressRaw(HMODULE hmod, PCSTR pszProcName); 33 | 34 | private: 35 | static PVOID sm_pvMaxAppAddr; // Maximum private memory address 36 | static CAPIHook* sm_pHead; // Address of first object 37 | CAPIHook* m_pNext; // Address of next object 38 | 39 | PCSTR m_pszCalleeModName; // Module containing the function (ANSI) 40 | PCSTR m_pszFuncName; // Function name in callee (ANSI) 41 | PROC m_pfnOrig; // Original function address in callee 42 | PROC m_pfnHook; // Hook function address 43 | 44 | private: 45 | // Replaces a symbol's address in a module's import section 46 | static void WINAPI ReplaceIATEntryInAllMods(PCSTR pszCalleeModName, 47 | PROC pfnOrig, PROC pfnHook); 48 | 49 | // Replaces a symbol's address in all modules' import sections 50 | static void WINAPI ReplaceIATEntryInOneMod(PCSTR pszCalleeModName, 51 | PROC pfnOrig, PROC pfnHook, HMODULE hmodCaller); 52 | 53 | // Replaces a symbol's address in a module's export sections 54 | static void ReplaceEATEntryInOneMod(HMODULE hmod, PCSTR pszFunctionName, PROC pfnNew); 55 | 56 | private: 57 | // Used when a DLL is newly loaded after hooking a function 58 | static void WINAPI FixupNewlyLoadedModule(HMODULE hmod, DWORD dwFlags); 59 | 60 | // Used to trap when DLLs are newly loaded 61 | static HMODULE WINAPI LoadLibraryA(PCSTR pszModulePath); 62 | static HMODULE WINAPI LoadLibraryW(PCWSTR pszModulePath); 63 | static HMODULE WINAPI LoadLibraryExA(PCSTR pszModulePath, 64 | HANDLE hFile, DWORD dwFlags); 65 | static HMODULE WINAPI LoadLibraryExW(PCWSTR pszModulePath, 66 | HANDLE hFile, DWORD dwFlags); 67 | 68 | // Returns address of replacement function if hooked function is requested 69 | static FARPROC WINAPI GetProcAddress(HMODULE hmod, PCSTR pszProcName); 70 | 71 | private: 72 | // Instantiates hooks on these functions 73 | static CAPIHook sm_LoadLibraryA; 74 | static CAPIHook sm_LoadLibraryW; 75 | static CAPIHook sm_LoadLibraryExA; 76 | static CAPIHook sm_LoadLibraryExW; 77 | static CAPIHook sm_GetProcAddress; 78 | }; 79 | 80 | 81 | //////////////////////////////// End of File ////////////////////////////////// 82 | -------------------------------------------------------------------------------- /22-LastMsgBoxInfoLib/LastMsgBoxInfoLib.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: LastMsgBoxInfoLib.h 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | 7 | #ifndef LASTMSGBOXINFOLIBAPI 8 | #define LASTMSGBOXINFOLIBAPI extern "C" __declspec(dllimport) 9 | #endif 10 | 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | LASTMSGBOXINFOLIBAPI BOOL WINAPI LastMsgBoxInfo_HookAllApps(BOOL bInstall, 16 | DWORD dwThreadId); 17 | 18 | 19 | //////////////////////////////// End of File ////////////////////////////////// 20 | -------------------------------------------------------------------------------- /23-SEHTerm/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by SEHTerm.rc 4 | // 5 | #define IDI_SEHTERM 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /23-SEHTerm/SEHTerm.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: SEHTerm.cpp 3 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 4 | ******************************************************************************/ 5 | 6 | #include "..\CommonFiles\CmnHdr.h" /* See Appendix A. */ 7 | #include 8 | #include 9 | 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | 14 | BOOL IsWindowsVista() { 15 | 16 | // Code from Chapter 4 17 | // Prepare the OSVERSIONINFOEX structure to indicate Windows Vista. 18 | OSVERSIONINFOEX osver = { 0 }; 19 | osver.dwOSVersionInfoSize = sizeof(osver); 20 | osver.dwMajorVersion = 6; 21 | osver.dwMinorVersion = 0; 22 | osver.dwPlatformId = VER_PLATFORM_WIN32_NT; 23 | 24 | // Prepare the condition mask. 25 | DWORDLONG dwlConditionMask = 0; // You MUST initialize this to 0. 26 | VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL); 27 | VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL); 28 | VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, VER_EQUAL); 29 | 30 | // Perform the version test. 31 | if (VerifyVersionInfo(&osver, VER_MAJORVERSION | VER_MINORVERSION | 32 | VER_PLATFORMID, dwlConditionMask)) { 33 | // The host system is Windows Vista exactly. 34 | return(TRUE); 35 | } else { 36 | // The host system is NOT Windows Vista. 37 | return(FALSE); 38 | } 39 | } 40 | 41 | 42 | void TriggerException() { 43 | 44 | __try { 45 | int n = MessageBox(NULL, TEXT("Perform invalid memory access?"), 46 | TEXT("SEHTerm: In try block"), MB_YESNO); 47 | 48 | if (n == IDYES) { 49 | * (PBYTE) NULL = 5; // This causes an access violation 50 | } 51 | } 52 | __finally { 53 | PCTSTR psz = AbnormalTermination() 54 | ? TEXT("Abnormal termination") : TEXT("Normal termination"); 55 | MessageBox(NULL, psz, TEXT("SEHTerm: In finally block"), MB_OK); 56 | } 57 | 58 | MessageBox(NULL, TEXT("Normal function termination"), 59 | TEXT("SEHTerm: After finally block"), MB_OK); 60 | } 61 | 62 | 63 | int WINAPI _tWinMain(HINSTANCE, HINSTANCE, PTSTR, int) { 64 | 65 | // In Windows Vista, a global unwind occurs if an except filter 66 | // returns EXCEPTION_EXECUTE_HANDLER. If an unhandled exception 67 | // occurs, the process is simply terminated and the finally blocks 68 | // are not exectuted. 69 | if (IsWindowsVista()) { 70 | 71 | DWORD n = MessageBox(NULL, TEXT("Protect with try/except?"), 72 | TEXT("SEHTerm: workflow"), MB_YESNO); 73 | 74 | if (n == IDYES) { 75 | __try { 76 | TriggerException(); 77 | } 78 | __except (EXCEPTION_EXECUTE_HANDLER) { 79 | // But the system dialog will not appear. 80 | // So, popup a message box. 81 | MessageBox(NULL, TEXT("Abnormal process termination"), 82 | TEXT("Process entry point try/except handler"), MB_OK); 83 | 84 | // Exit with a dedicated error code 85 | return(-1); 86 | } 87 | } else { 88 | TriggerException(); 89 | } 90 | } else { 91 | TriggerException(); 92 | } 93 | 94 | MessageBox(NULL, TEXT("Normal process termination"), 95 | TEXT("SEHTerm: before leaving the main thread"), MB_OK); 96 | 97 | return(0); 98 | } 99 | 100 | 101 | //////////////////////////////// End of File ////////////////////////////////// 102 | -------------------------------------------------------------------------------- /23-SEHTerm/SEHTerm.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/23-SEHTerm/SEHTerm.ico -------------------------------------------------------------------------------- /23-SEHTerm/SEHTerm.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_SEHTERM ICON DISCARDABLE "SEHTerm.ICO" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE DISCARDABLE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE DISCARDABLE 45 | BEGIN 46 | "#include ""Windows.h""\r\n" 47 | "\0" 48 | END 49 | 50 | 3 TEXTINCLUDE DISCARDABLE 51 | BEGIN 52 | "\r\n" 53 | "\0" 54 | END 55 | 56 | #endif // APSTUDIO_INVOKED 57 | 58 | #endif // English (U.S.) resources 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | 63 | #ifndef APSTUDIO_INVOKED 64 | ///////////////////////////////////////////////////////////////////////////// 65 | // 66 | // Generated from the TEXTINCLUDE 3 resource. 67 | // 68 | 69 | 70 | ///////////////////////////////////////////////////////////////////////////// 71 | #endif // not APSTUDIO_INVOKED 72 | 73 | -------------------------------------------------------------------------------- /25-Spreadsheet/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by Spreadsheet.rc 4 | // 5 | #define IDC_STATIC (-1) // all static controls 6 | #define IDD_SPREADSHEET 1 7 | #define IDC_LOG 101 8 | #define IDI_SPREADSHEET 102 9 | #define IDC_ROW 1001 10 | #define IDC_COLUMN 1002 11 | #define IDC_COLUMN2 1003 12 | #define IDC_VALUE 1003 13 | #define IDC_READCELL 1004 14 | #define IDC_WRITECELL 1005 15 | 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | #define _APS_NEXT_RESOURCE_VALUE 103 21 | #define _APS_NEXT_COMMAND_VALUE 40001 22 | #define _APS_NEXT_CONTROL_VALUE 1007 23 | #define _APS_NEXT_SYMED_VALUE 101 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /25-Spreadsheet/Spreadsheet.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/25-Spreadsheet/Spreadsheet.ico -------------------------------------------------------------------------------- /25-Spreadsheet/Spreadsheet.rc: -------------------------------------------------------------------------------- 1 | //Microsoft Developer Studio generated resource script. 2 | // 3 | #include "Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "Windows.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE DISCARDABLE 31 | BEGIN 32 | "Resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE DISCARDABLE 36 | BEGIN 37 | "#include ""Windows.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE DISCARDABLE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Dialog 53 | // 54 | 55 | IDD_SPREADSHEET DIALOG DISCARDABLE 18, 18, 164, 165 56 | STYLE DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 | CAPTION "Spreadsheet" 58 | FONT 8, "MS Sans Serif" 59 | BEGIN 60 | LTEXT "Cell size:\nRows:\nColumns:\nTotal size:",IDC_STATIC,4, 61 | 4,36,36 62 | LTEXT "1024 bytes\n256\n1024\n256 MB (268,435,456 bytes)", 63 | IDC_STATIC,44,4,104,36 64 | LTEXT "R&ow (0-255):",IDC_STATIC,4,56,42,8 65 | EDITTEXT IDC_ROW,60,52,40,14,ES_AUTOHSCROLL | ES_NUMBER 66 | LTEXT "&Column (0-1023):",IDC_STATIC,4,76,54,8 67 | EDITTEXT IDC_COLUMN,60,72,40,14,ES_AUTOHSCROLL | ES_NUMBER 68 | PUSHBUTTON "&Read Cell",IDC_READCELL,108,72,50,14 69 | LTEXT "&Value:",IDC_STATIC,4,96,21,8 70 | EDITTEXT IDC_VALUE,60,92,40,14,ES_AUTOHSCROLL | ES_NUMBER 71 | PUSHBUTTON "&Write Cell",IDC_WRITECELL,108,92,50,14 72 | LTEXT "Execution lo&g:",IDC_STATIC,4,118,48,8 73 | EDITTEXT IDC_LOG,4,132,156,28,ES_MULTILINE | ES_AUTOHSCROLL | 74 | ES_READONLY 75 | END 76 | 77 | 78 | ///////////////////////////////////////////////////////////////////////////// 79 | // 80 | // Icon 81 | // 82 | 83 | // Icon with lowest ID value placed first to ensure application icon 84 | // remains consistent on all systems. 85 | IDI_SPREADSHEET ICON DISCARDABLE "Spreadsheet.Ico" 86 | #endif // English (U.S.) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /26-CustomizedWER/CustomizedWER.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /26-CustomizedWER/CustomizedWER.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/26-CustomizedWER/CustomizedWER.ico -------------------------------------------------------------------------------- /26-CustomizedWER/CustomizedWER.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (U.S.) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | #ifdef _WIN32 22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 23 | #pragma code_page(1252) 24 | #endif //_WIN32 25 | 26 | #ifdef APSTUDIO_INVOKED 27 | ///////////////////////////////////////////////////////////////////////////// 28 | // 29 | // TEXTINCLUDE 30 | // 31 | 32 | 1 TEXTINCLUDE 33 | BEGIN 34 | "resource.h\0" 35 | END 36 | 37 | 2 TEXTINCLUDE 38 | BEGIN 39 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 40 | "#include ""windows.h""\r\n" 41 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 42 | "\0" 43 | END 44 | 45 | 3 TEXTINCLUDE 46 | BEGIN 47 | "\r\n" 48 | "\0" 49 | END 50 | 51 | #endif // APSTUDIO_INVOKED 52 | 53 | 54 | ///////////////////////////////////////////////////////////////////////////// 55 | // 56 | // Dialog 57 | // 58 | 59 | IDD_MAINDLG DIALOGEX 0, 0, 184, 76 60 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU 61 | CAPTION "Customized WER" 62 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 63 | BEGIN 64 | DEFPUSHBUTTON "Access Violation",IDOK,101,4,78,68 65 | GROUPBOX "Shutdown behavior",IDC_STATIC,2,1,93,72 66 | CONTROL "Default",IDR_DEFAULT,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,9,15,51,10 67 | CONTROL "Custom",IDR_CUSTOM,"Button",BS_AUTORADIOBUTTON,9,30,50,10 68 | CONTROL "Allow Debug",IDC_ALLOW_DEBUG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,43,61,10 69 | CONTROL "Generate a report",IDC_GENERATE_REPORT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,56,73,10 70 | END 71 | 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | // 75 | // Icon 76 | // 77 | 78 | // Icon with lowest ID value placed first to ensure application icon 79 | // remains consistent on all systems. 80 | IDI_MAINDLG ICON "CustomizedWER.ico" 81 | 82 | ///////////////////////////////////////////////////////////////////////////// 83 | // 84 | // DESIGNINFO 85 | // 86 | 87 | #ifdef APSTUDIO_INVOKED 88 | GUIDELINES DESIGNINFO 89 | BEGIN 90 | IDD_MAINDLG, DIALOG 91 | BEGIN 92 | LEFTMARGIN, 7 93 | RIGHTMARGIN, 177 94 | TOPMARGIN, 7 95 | BOTTOMMARGIN, 69 96 | END 97 | END 98 | #endif // APSTUDIO_INVOKED 99 | 100 | #endif // English (U.S.) resources 101 | ///////////////////////////////////////////////////////////////////////////// 102 | 103 | 104 | 105 | #ifndef APSTUDIO_INVOKED 106 | ///////////////////////////////////////////////////////////////////////////// 107 | // 108 | // Generated from the TEXTINCLUDE 3 resource. 109 | // 110 | 111 | 112 | ///////////////////////////////////////////////////////////////////////////// 113 | #endif // not APSTUDIO_INVOKED 114 | 115 | -------------------------------------------------------------------------------- /26-CustomizedWER/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by HandleUnhandled.rc 4 | // 5 | #define IDI_MAINDLG 130 6 | #define IDD_MAINDLG 131 7 | #define IDR_DEFAULT 1001 8 | #define IDR_CUSTOM 1002 9 | #define IDC_ALLOW_DEBUG 1003 10 | #define IDC_GENERATE_REPORT 1004 11 | #define IDC_STATIC -1 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NO_MFC 1 18 | #define _APS_NEXT_RESOURCE_VALUE 132 19 | #define _APS_NEXT_COMMAND_VALUE 32771 20 | #define _APS_NEXT_CONTROL_VALUE 1004 21 | #define _APS_NEXT_SYMED_VALUE 110 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /Clean.bat: -------------------------------------------------------------------------------- 1 | @echo Off 2 | del /s /a *.txt *.exe *.suo *.ncb *.user *.dll *.pdb *.netmodule *.aps *.ilk 2>nul 3 | FOR /R . %%d IN (.) DO rd /s /q "%%d\x64" 2>nul 4 | FOR /R . %%d IN (.) DO rd /s /q "%%d\Debug" 2>nul 5 | FOR /R . %%d IN (.) DO rd /s /q "%%d\Release" 2>nul 6 | FOR /R . %%d IN (.) DO rd /s /q "%%d\Bin" 2>nul 7 | FOR /R . %%d IN (.) DO rd /s /q "%%d\Obj" 2>nul 8 | 9 | rem If the Properties directory is empty, remove it 10 | FOR /R . %%d in (.) do rd /q "%%d\Properties" 2> nul 11 | -------------------------------------------------------------------------------- /CommonFiles/IoCompletionPort.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: IOCP.h 3 | Notices: Copyright (c) 2007 Jeffrey Richter & Christophe Nasarre 4 | Purpose: This class wraps an I/O Completion Port. 5 | See Appendix B. 6 | ******************************************************************************/ 7 | 8 | 9 | #pragma once // Include this header file once per compilation unit 10 | 11 | 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | #include "..\CommonFiles\CmnHdr.h" // See Appendix A. 16 | 17 | 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | 21 | class CIOCP { 22 | public: 23 | CIOCP(int nMaxConcurrency = -1) { 24 | m_hIOCP = NULL; 25 | if (nMaxConcurrency != -1) 26 | (void) Create(nMaxConcurrency); 27 | } 28 | 29 | ~CIOCP() { 30 | if (m_hIOCP != NULL) 31 | chVERIFY(CloseHandle(m_hIOCP)); 32 | } 33 | 34 | 35 | BOOL Close() { 36 | BOOL bResult = CloseHandle(m_hIOCP); 37 | m_hIOCP = NULL; 38 | return(bResult); 39 | } 40 | 41 | BOOL Create(int nMaxConcurrency = 0) { 42 | m_hIOCP = CreateIoCompletionPort( 43 | INVALID_HANDLE_VALUE, NULL, 0, nMaxConcurrency); 44 | chASSERT(m_hIOCP != NULL); 45 | return(m_hIOCP != NULL); 46 | } 47 | 48 | BOOL AssociateDevice(HANDLE hDevice, ULONG_PTR CompKey) { 49 | BOOL fOk = (CreateIoCompletionPort(hDevice, m_hIOCP, CompKey, 0) 50 | == m_hIOCP); 51 | chASSERT(fOk); 52 | return(fOk); 53 | } 54 | 55 | BOOL AssociateSocket(SOCKET hSocket, ULONG_PTR CompKey) { 56 | return(AssociateDevice((HANDLE) hSocket, CompKey)); 57 | } 58 | 59 | BOOL PostStatus(ULONG_PTR CompKey, DWORD dwNumBytes = 0, 60 | OVERLAPPED* po = NULL) { 61 | 62 | BOOL fOk = PostQueuedCompletionStatus(m_hIOCP, dwNumBytes, CompKey, po); 63 | chASSERT(fOk); 64 | return(fOk); 65 | } 66 | 67 | BOOL GetStatus(ULONG_PTR* pCompKey, PDWORD pdwNumBytes, 68 | OVERLAPPED** ppo, DWORD dwMilliseconds = INFINITE) { 69 | 70 | return(GetQueuedCompletionStatus(m_hIOCP, pdwNumBytes, 71 | pCompKey, ppo, dwMilliseconds)); 72 | } 73 | 74 | private: 75 | HANDLE m_hIOCP; 76 | }; 77 | 78 | 79 | ///////////////////////////////// End of File ///////////////////////////////// 80 | -------------------------------------------------------------------------------- /CommonFiles/WaitChainTraversal.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Module: WaitChainTransversal.h 3 | Details: Helper class for the "Wait Chain Transversal" API 4 | Notices: Copyright (c) 2008 Jeffrey Richter & Christophe Nasarre 5 | ******************************************************************************/ 6 | 7 | 8 | #pragma once 9 | 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | 13 | 14 | #include "CmnHdr.h" /* See Appendix A. */ 15 | #include "Toolhelp.h" 16 | #include 17 | #include 18 | 19 | 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | 23 | class CWCT 24 | { 25 | public: 26 | CWCT(); 27 | ~CWCT(); 28 | 29 | // Enumerate all the threads running in the given process, 30 | // and for each, dump the wait chain 31 | void ParseThreads(DWORD PID); 32 | 33 | 34 | protected: 35 | // Implement this method to be called before each thread is analyzed 36 | // Note: if nodeCount is 0, it was not possible to analyze this thread 37 | virtual void OnThread(DWORD TID, BOOL bDeadlock, DWORD nodeCount); 38 | 39 | // Implement this method to be called for each wait node 40 | virtual void OnChainNodeInfo(DWORD rootTID, DWORD currentNode, 41 | WAITCHAIN_NODE_INFO nodeInfo); 42 | 43 | // Return the number of nodes in the current thread chain 44 | DWORD GetNodesInChain(); 45 | 46 | // Return the PID of the parsed process 47 | DWORD GetPID(); 48 | 49 | 50 | private: 51 | void InitCOM(); 52 | void ParseThread(DWORD TID); 53 | 54 | 55 | private: 56 | // Handle of the WCT session 57 | HWCT _hWCTSession; 58 | 59 | // Handle of OLE32.DLL module 60 | HMODULE _hOLE32DLL; 61 | 62 | DWORD _PID; 63 | DWORD _dwNodeCount; 64 | }; 65 | 66 | 67 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | 70 | 71 | CWCT::CWCT() { 72 | 73 | _hOLE32DLL = NULL; 74 | 75 | // Open the WCT session in synchronous mode 76 | _hWCTSession = OpenThreadWaitChainSession(0, NULL); 77 | if (_hWCTSession == NULL) 78 | return; 79 | 80 | // It is also possible to detect locks on COM calls 81 | InitCOM(); 82 | } 83 | 84 | 85 | void CWCT::InitCOM() { 86 | 87 | PCOGETCALLSTATE CallStateCallback; 88 | PCOGETACTIVATIONSTATE ActivationStateCallback; 89 | 90 | // Load OLE32.DLL into the process to be able to get the address 91 | // of the two COM functions required by RegisterWaitChainCOMCallback 92 | _hOLE32DLL = LoadLibrary(TEXT("OLE32.DLL")); 93 | 94 | CallStateCallback = (PCOGETCALLSTATE) 95 | GetProcAddress(_hOLE32DLL, "CoGetCallState"); 96 | ActivationStateCallback = (PCOGETACTIVATIONSTATE) 97 | GetProcAddress(_hOLE32DLL, "CoGetActivationState"); 98 | 99 | // Pass these COM helper functions to WCT 100 | RegisterWaitChainCOMCallback(CallStateCallback, ActivationStateCallback); 101 | } 102 | 103 | 104 | CWCT::~CWCT() { 105 | 106 | // Don't forget to unload OLE32.DLL 107 | if (_hOLE32DLL != NULL) { 108 | FreeLibrary(_hOLE32DLL); 109 | } 110 | 111 | // Don't forget to close the WCT session 112 | if (_hWCTSession != NULL) { 113 | CloseThreadWaitChainSession(_hWCTSession); 114 | } 115 | } 116 | 117 | 118 | void CWCT::ParseThreads(DWORD PID) { 119 | 120 | _PID = PID; 121 | 122 | // List all threads in the given process 123 | CToolhelp th(TH32CS_SNAPTHREAD, PID); 124 | THREADENTRY32 te = { sizeof(te) }; 125 | BOOL fOk = th.ThreadFirst(&te); 126 | for (; fOk; fOk = th.ThreadNext(&te)) { 127 | // Only parse threads of the given process 128 | if (te.th32OwnerProcessID == PID) { 129 | ParseThread(te.th32ThreadID); 130 | } 131 | } 132 | } 133 | 134 | 135 | void CWCT::ParseThread(DWORD TID) { 136 | 137 | WAITCHAIN_NODE_INFO chain[WCT_MAX_NODE_COUNT]; 138 | DWORD dwNodesInChain; 139 | BOOL bDeadlock; 140 | 141 | dwNodesInChain = WCT_MAX_NODE_COUNT; 142 | 143 | // Get the chain for the current thread 144 | if (!GetThreadWaitChain(_hWCTSession, NULL, WCTP_GETINFO_ALL_FLAGS, 145 | TID, &dwNodesInChain, chain, &bDeadlock)) { 146 | 147 | _dwNodeCount = 0; 148 | OnThread(TID, FALSE, 0); 149 | return; 150 | } 151 | 152 | // Start the chain processing for the current thread 153 | _dwNodeCount = min(dwNodesInChain, WCT_MAX_NODE_COUNT); 154 | OnThread(TID, bDeadlock, dwNodesInChain); 155 | 156 | // For each node in the chain, call the virtual method with details 157 | for ( 158 | DWORD current = 0; 159 | current < min(dwNodesInChain, WCT_MAX_NODE_COUNT); 160 | current++ 161 | ) { 162 | OnChainNodeInfo(TID, current, chain[current]); 163 | } 164 | } 165 | 166 | 167 | DWORD CWCT::GetNodesInChain() { 168 | 169 | return(_dwNodeCount); 170 | } 171 | 172 | 173 | DWORD CWCT::GetPID() { 174 | 175 | return(_PID); 176 | } 177 | 178 | 179 | void CWCT::OnThread(DWORD TID, BOOL bDeadlock, DWORD nodeCount) { 180 | 181 | // Virtual method to be implemented by derived classes 182 | } 183 | 184 | 185 | void CWCT::OnChainNodeInfo(DWORD rootTID, DWORD currentNode, 186 | WAITCHAIN_NODE_INFO nodeInfo) { 187 | 188 | // Virtual method to be implemented by derived classes 189 | } 190 | 191 | 192 | 193 | //////////////////////////////// End of File ////////////////////////////////// 194 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming-Applications-for-Microsoft-Windows 2 | -------------------------------------------------------------------------------- /windows-via-cplusplus-code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yiminyangguang520/Programming-Applications-for-Microsoft-Windows/d4a2ae7722209f95b07b6c9a4189b28ceab722a0/windows-via-cplusplus-code.zip --------------------------------------------------------------------------------