本书是《微软编程圣典丛书(影印版)》之一,讲述如何利用各种高级特性和最新技巧开发32位和64位Windows应用程序,内容涉及Windows 2000中的各种特性,API和DLL,进程和线程,结构化异常情况处理等。为了增加本书的实用性,特以配套光盘的形式提供了丰富的程序实例以及本书的电子版。\r\n 本书由微软公司组织专家编写,具有相当的技术深度,是中、高级程序员必备的参考书。\r\n
PARTⅠ:REQUIRED READING\r\n\r\nCHAPTER ONE ERROR HANDLING\r\n\r\nYou Can This Too\r\nThe ErrorShow Sample Application\r\n\r\nCHAPTER TWO UNICODE\r\n\r\nCharacter Sets\r\n\r\nSingle-Byte and Double-Byte Character Sets\r\nUnicode:The Wide-Byte Character Set\r\n\r\nWhy You Should Use Unicode\r\n\r\nWindows 2000 and Unicode\r\n\r\nWindows 98 and Unicode\r\n\r\nWindows CE and Unicode\r\n\r\nKeeping Score\r\n\r\nA Quick Word About COM\r\n\r\nHow to Write Unicode Source Code\r\n\r\nUnicode Support in the C Run-Time Library\r\nUnicode Data Types Defined by Windows\r\nUnicode and ANSI Functions in Winodows\r\nWindows String Functions\r\n\r\nMaking Your Application ANSI-and Unicode-Ready\r\n\r\nWindows String Functions\r\nResources\r\nDetermining If Text Is ANSI or Unicode\r\nTranslating Strings Between Unicode and ANSI\r\n\r\nCHAPTER THREE KERNEL OBJECTS\r\n\r\nWhat Is a Kernel Object?\r\n\r\nUsage Counting\r\nSecurity\r\n\r\nA Process’s Kernel Object Handle Table\r\n\r\nCreating a Kernel Object\r\nClosing a Kernel Object\r\n\r\nSharing Kernel Objects Across Process Boundaries\r\n\r\nObject Handle Inheritance\r\nNamed Objects\r\nDuplicating Object Handles\r\n\r\nPARTⅡ:GETTING WORK DONE\r\n\r\nCHAPTER FOUR PROCESSES\r\n\r\nWriting Your First Windows Application\r\n\r\nA Process’s Instance Handle\r\nA Process’s Previous Instance Handle\r\nA Process’s Command Line\r\nA Process’s Environment Variables\r\nA Process’s Affinity\r\nA Process’s Error Mode\r\nA Process’s Current Drive and Directory\r\nThe System Version\r\n\r\nThe CreateProcess Function\r\n\r\npszApplicationName and pszCommandLine\r\npsaProcess,psaThread,and blnheritHandles\r\nfdwCreate\r\npvEnvironment\r\npszCurDir\r\npsiStartInfo\r\nppiProcInfo\r\n\r\nTerminating a Process\r\n\r\nThe Primary Thread’s Entry-Point Function Returns\r\nThe ExitProcess Function\r\nThe TerminateProcess Function\r\nWhen All the Threads in the Process Die\r\nWhen a Process Terminates\r\n\r\nChild Process\r\n\r\nRunning Detached Child Processes\r\n\r\nEnumerating the Processes Running in the System\r\n\r\nCHAPTER FIVE JOBS\r\n\r\nPlacing Restrictions on a Job’s Processes\r\n\r\nPlacing a Process in a Job\r\n\r\nTerminating All Processes in a Job\r\n\r\nQuerying Job Statistics\r\n\r\nJob Notifiacations\r\n\r\nThe JobLab Sample Application\r\n\r\nCHAPTER SIX THREAD BASICS\r\n\r\nWhen to Create a Thread\r\n\r\nWhen Not to Create a Thread\r\n\r\nWriting Your First Thread Function\r\n\r\nThe Create Thread Function\r\n\r\npsa\r\ncbStack\r\npfnStartAddr and pbParam\r\npdwThreadID\r\n\r\nTerminating a Thread\r\n\r\nThe Thread Function Returns\r\nThe ExitThread Function\r\nThe Terminate Thread Function\r\nWhen a Process Terminates\r\nWhen a Thread Terminates\r\n\r\nSome Thread Internals\r\n\r\nC/C++ Run-Time Library Considerations\r\n\r\nOops—I Called CreateThread Instead of _beginthreadex by Mistake\r\nC/C++ Run-Time Lbbrary Functions That You Should Never Call\r\n\r\nGaining a Sense of One’s Own Identity\r\n\r\nConverting a Pseudo-Handle to a Real Handle\r\n\r\nCHAPTER SEVER THREAD SCHEDULING,PRIORITIES,AND AFFINITIES\r\n\r\nSuspending and Resuming a Thread\r\n\r\nSuspending and Resuming a Process\r\n\r\nSleeping\r\n\r\nSwitching to Another Thread\r\n\r\nA Thread’s Execution Times\r\n\r\nPutting the Context in Context\r\n\r\nThread Priorities\r\n\r\nAn Abstract View of Priorities\r\n\r\nProgramming Priorities\r\n\r\nDynamically Boosting Thread Priority Levels\r\nTweaking the Scheduler for the Foreground Process\r\nThe Scheduling Lab Sample Application\r\n\r\nAffinities\r\n\r\nCHAPTER EIGHT THREAD SYNCHRONIZATION IN USER MODE\r\n\r\nAtomic Access:The Interlocked Family fo Functions\r\n\r\nCache Lines\r\n\r\nAdvanced Thread Synchronization\r\n\r\nA Technique to Avoid\r\n\r\nCritical Sections\r\n\r\nCritical Sections:The Fine Print\r\nCritical Sections and Spinlocks\r\nCritical Sections and Error Handing\r\nUseful Tips and Techniques\r\n\r\nCHAPTER NINE THREAD SYNCHRONIZATION WITH KERNEL OBJECTS\r\n\r\nWait Functions\r\n\r\nSuccessful Wait Side Effects\r\n\r\nEvent Kernel Objects\r\n\r\nThe Handshake Sample Application\r\n\r\nWaitable Timer Kernel Objects\r\n\r\nHaving Waitable Timers Queue APC Entries\r\nTimer Loose Ends\r\n\r\nSemaphore Kernel Objects\r\n\r\nMutex Kernel Objects\r\n\r\nAbandonment Issues\r\nMutexes vs.Crivical Sections\r\nThe Queue Sample Application\r\n\r\nA Handy Thread Synchronization Object Chart\r\n\r\nOther Thread Synchronization Functions\r\n\r\nAsynchronous Device I/O\r\nWartForInputIdle\r\nMsgWaitForMultipleObjects(Ex)\r\nWaitForDebugEvent\r\nSignalObjectAndWait\r\n\r\nCHAPTER TEN THREAD SYNCHRONIZATION TOOLKIT\r\n\r\nImplementing a Critical Section:The Optex\r\n\r\nThe Optex Sample Application\r\n\r\nCreating Thread-Safe Datatypes and Inverse Semaphores\r\n\r\nThe InterlockedType Sample Application\r\n\r\nThe Single Writer/Multiple Reader Guard(SWMRG)\r\n\r\nThe SWMRG Sample Application\r\n\r\nImplementing a WaitForMultipleExpressions Function\r\n\r\nThe WaitForMultipleExpressions Sample Application\r\n\r\nCHAPTER ELEVER THREAD POOLING\r\n\r\nScenario1:Call Functions Asynchronously\r\n\r\nScenario2:Call Functions at Timed Intervals\r\n\r\nThe TimedMsgBox Sample Application\r\n\r\nScenario3:Call Functions When Single Kernel Objects Become Signaled\r\n\r\nScenario4:Call Functions When Asynchronous I/O Requests Complete\r\n\r\nCHAPTER TWELVE FIBERS\r\n\r\nWorking with Fibers\r\n\r\nThe Counter Sample Application\r\n\r\nPARTⅢ:MEMORY MANAGEMENT\r\n\r\nCHAPTER THIRTEEN WINDOWS MEMORY ARCHITECTURE\r\n\r\nA Process’s Virtual Address Space How a Virtual Address Space Is Partitioned\r\n\r\nNull-Pointer Assignment Partition(Windows 2000 and Windows 98)\r\nMS-DOS/16-Bit Windows Application Compatibility Partition(Windows 98 Only)\r\nUser-Mode Partition (Windows 2000 and Windows 98)\r\n64-KB Off-Limits Partition(Windows 2000 Only)\r\nShared MMF Partition(Windows 98 Only)\r\nKernel-Mode Partition(Windows 2000 and Windows 98)\r\n\r\nRegions in an Address Space\r\n\r\nCommitting Physical Storage Within a Region\r\n\r\nPhysical Storage and the Paging File\r\n\r\nPhysical Storage Not Maintained in the Paging File\r\n\r\nProtection Attributes\r\n\r\nCopy-On-Write Access\r\nSpecial Access Protection Attribute Flags\r\n\r\nBringing It All Home\r\n\r\nInside the Regions\r\nAddress Space Differences for Windows 98\r\n\r\nThe Importance of Data Alignment\r\n\r\nCHAPTER FOURTEEN EXPLORING VIRTUAL MEMORY\r\n\r\nSystem Information\r\n\r\nThe System Information Sample Application\r\n\r\nVirtual Memory Status\r\n\r\nThe Virtual Memory Status Sample Application\r\n\r\nDetermining the State of an Address Space\r\n\r\nThe VMQuery Function\r\nThe Virtual Memory Map Sample Application\r\n\r\nCHAPTER FIFTEEN USING VIRTUAL MEMORY IN YOUR OWN APPLICATIONS\r\n\r\nReserving a Region in an Address Space\r\n\r\nCommitting Storage in a Reserved Region\r\n\r\nReserving a Region and Committing Storage Simultaneously\r\n\r\nWhen to Commit Physical Storage\r\n\r\nDecommitting Physical Storage and Releasing a Region\r\n\r\nWhen to Decommit Physical Storage\r\nThe Virtual Memory Allocation Sample Application\r\n\r\nChanging Protection Attributes\r\n\r\nResetting the Contents of Physical Storage\r\n\r\nThe MemReset Sample Application\r\n\r\nAddress Windowing Extensions(Windows 2000 only)\r\n\r\nThe AWE Sample Application\r\n\r\nCHAPTER SIXTEEN A THREAD’S STACK\r\n\r\nA Thread’s Stack Under Window 98\r\nThe C/C++Run-Time Library’s Stack-Checking Function\r\nThe Summation Sample Application\r\n\r\nCHAPTER SEVENTEEN MEMORY-MAPPED FILES\r\n\r\nMemory-Mapped Executables and DLLS\r\n\r\nStatic Data Is Not Shared by Multiple Instances of an Executable or a DLL\r\nSharing Static Data Across Multiple Instances of an Executable or a DLL\r\nThe AppInst Sample Application\r\n\r\nMemory-Mapped Data Files\r\n\r\nMethod1:One File,One Buffer\r\nMethod2:Two File,One Buffer\r\nMethod3:One File,Two Buffer\r\nMethod4:One File,Zero Buffers\r\n\r\nUsing Memory-Mapped Files\r\n\r\nStep1:Creating or Opening a File Kernel Object\r\nStep2:Creating a File-Mapping Kernel Object\r\nStep3:Mapping the File’s Data into the Process’s Address Space\r\nStep4:Unmapping the File’s Data from the Process’s Address Space\r\nStep5 and 6:Closing the File-Mapping Object and the File Object\r\nThe File Reverse Sample Application\r\n\r\nProcessing a Big File Using Memory-Mapped Files\r\n\r\nMemory-Mapped Files and Coherence\r\n\r\nSpecifying the Base Address of a Memory-Mapped File\r\n\r\nImplementation Details of Memory-Mapped Files\r\n\r\nUsing Memory-Mapped Files to Shore Data Among Processes\r\n\r\nMemory-Mapped Files Backed by the Paging File\r\n\r\nThe Memory-Mapped File Sharing Sample Application\r\n\r\nSparsely Committed Memory-Mapped Files\r\n\r\nThe Sparse Memory-Mapped File Sample Application\r\n\r\nCHAPTER EIGHTEEN HEAPS\r\n\r\nA Proess’s Default Heap\r\n\r\nReasons to Create Additional Heaps\r\n\r\nComponent Protection\r\nMore Efficient Memory Management\r\nLocal Access\r\nAvoiding Thread Synchronization Overhead\r\nQuick Free\r\n\r\nHow to Create an Additional Heap\r\n\r\nAllocating a Block of Memory from a Heap\r\nChanging the Size of a Block\r\nObtaining the Size of a Block\r\nFreeing a Block\r\nDestroying a Heap\r\nUsing Heaps with C++\r\n\r\nPARTⅣ:DYNAMIC-LINK LIBRARIES\r\n\r\nCHAPTER NINETEEN DLL BASICS\r\n\r\nDLLs and a Process’s Address Space\r\n\r\nThe Overall Picture\r\n\r\nBuilding the DLL Module\r\n\r\nWhat Exporting Really Means\r\nCreating DLLs for Use with Non-Visual C++ Tools\r\n\r\nBuilding the Executable Module\r\n\r\nWhat Importing Really Means\r\n\r\nRunning the Executable Module\r\n\r\nCHAPTER TWENTY DLL ADVANCED TECHNIQUES\r\n\r\nExplicit DLL Module Loading and Symbol Linking\r\n\r\nExplicitly Loading the DLL Module\r\nExplicitly Unloading the DLL Module\r\nExplicitly Linking to an Exported Symbol\r\n\r\nThe DLL’s Entry-Point Function\r\n\r\nThe DLL_PROCESS_ATTACH Notification\r\nThe DLL_PROCESS_DETCH Notification\r\nThe DLL_THREAD_ATTACH Notification\r\nThe DLL_THREAD_DETACH Notification\r\nSerialized Calls to D//Main\r\nD//Main and the C/C++ Run-Time Library\r\n\r\nDelay-Loading a DLL\r\n\r\nThe DelayLoadApp Sample Application\r\n\r\nFunction Forwarders\r\n\r\nKnown DLLs\r\n\r\nDLL Redirection\r\n\r\nRebasing Modules\r\n\r\nBind Modules\r\n\r\nCHAPTER TWENTY-ONE THREAD-LOCAL STORAGE\r\n\r\nDynamic TLS\r\n\r\nUsing Dynamic TLS\r\n\r\nStatic TLS\r\n\r\nCHAPTER TWENTY-TWO DLL INJECTION AND API HOOKING\r\n\r\nDLL Injection:An Example\r\n\r\nInjecting a DLL Using the Rgistry\r\n\r\nInjecting a DLL Using Windows Hooks\r\n\r\nThe Desktop Item Position Saver(DIPS)Utility\r\n\r\nInjecting a DLL Using Remote Threads\r\n\r\nThe Inject Library Sample Application\r\nThe Image Walk DLL\r\n\r\nInjecting a DLL with a Trojan DLL\r\n\r\nInjecting a DLL as a Debugger\r\n\r\nInjecting Code with a Memory-Mapped File on Windows 98\r\n\r\nInjecting Code with CreateProcess\r\n\r\nAPI Hooking:An Example\r\n\r\nAPI Hooking by Overwriting Code\r\nAPI Hooking by Module’s Import Section\r\nThe LastMsgBoxInfo Sample Application\r\n\r\nPARTⅤ:STRUCTURED EXCEPTION HANDLING\r\n\r\nCHAPTER TWENTY-THREE TERMINATION HANDLERS\r\n\r\nUnderstanding Termination Handlers by Example\r\n\r\nFuncenstein1\r\nFuncenstein2\r\nFuncenstein3\r\nFuncfurter1\r\nPop Quiz Time:FuncaDoodleDoo\r\nFuncenstein4\r\nFuncarama1\r\nFuncarama2\r\nFuncarama3\r\nFuncarama4:The Final Frontier\r\nNotes About the finally Block\r\nFuncfurter2\r\nThe SEH Termination Sample Application\r\n\r\nCHAPTER TWENTY-FOUR EXCEPTION HANDLERS AND SOFTWARE EXCEPTIONS\r\n\r\nUnderstanding Exception Filters and Exception Handlers by Example\r\n\r\nFuncmeister1\r\nFuncmeister2\r\n\r\nEXCEPTION_EXECUTE_HANDLER\r\n\r\nSome Useful Examples\r\nGolbal Unwinds\r\nHalting Golbal Unwinds\r\n\r\nEXCEPTION_CONTINUE_EXECUTION\r\n\r\nUse EXCEPTION_CONTINUE_EXECUTION with Caution\r\n\r\nEXCEPTION_CONTINUE_SEARCH\r\n\r\nGetExceptinCode\r\n\r\nMemory-Related Exceptions\r\nException-Related Exceptions\r\nDebugging-Related Exceptions\r\nInteger-Related Exceptions\r\nFloating Point-Related Exceptions\r\n\r\nGetExceptionInfomation\r\n\r\nSoftware Exceptions\r\n\r\nCHAPTER TWENTY-FIVE NUHANDLED EXCEPTIONS AND C++ EXCEPTIONS\r\n\r\nJust-In-Time Debugging\r\n\r\nTurning off the Exception Message Box\r\n\r\nForcing the Process to Die\r\nWrapping a Thread Function\r\nWrapping All Thread Functions\r\nAutomatically Invoking the Debugger\r\n\r\nCalling UnhandledExceptionFilter Yourself\r\n\r\nInside the UnhandledExceptionFilter Function\r\n\r\nExceptions and the Debugger\r\n\r\nThe Spreadsheet Sample Application\r\n\r\nC++ Exceptions Versus Structured Exceptions\r\n\r\nCatching Structured Exceptions with C++\r\n\r\nPARTⅥ:WINDOWING\r\n\r\nCHAPTER TWENTY-SIX WINDOW MESSAGING\r\n\r\nA Thread’s Message Queue\r\n\r\nPosting Messages to a Thread’s Message Queue\r\n\r\nSending Messages to a Window\r\n\r\nWaking a Thread\r\n\r\nThe Queue Status Flags\r\nThe Algorithm for Extracting Messages from a Thread’s Queue\r\nWaking a Thread with Kernel Objects or with Queue Status Flags\r\n\r\nSending Data with Messages\r\n\r\nThe CopyData Sample Application\r\n\r\nHow Windows Handle ANSI/Unicode Characters and Strings\r\n\r\nCHAPTER TWENTY-SEVEN THE HARDWARE INPUT MODEL AND LOCAL INPUT STATE\r\n\r\nThe Raw Input Thread\r\n\r\nLocal Input State\r\n\r\nKeyboard Input and Focus\r\nMouse Cursor Management\r\n\r\nAttaching Virtualized Input Queues and Local Input State Together\r\n\r\nThe Local Input State Laboratory(LISLab) Sample Application\r\nThe Local Input State Watch(LISWatch)Sample Application\r\n\r\nAPPENDIX A THE BUILD ENVIRONMENT\r\n\r\nThe CmnHdr.h Header File\r\n\r\nWindows Version Build Option\r\nUnicode Build Option\r\nWindows Definitions and Warning Level 4\r\nThe Pragma Message Helper Macro\r\nThe chINRANGE and chDIMOF Macros\r\nThe chBEGINTHREADEX Macro\r\nDebugBreak Improvement for 86 Platforms\r\nCreating Software Exception Codes\r\nThe chMB Macro\r\nThe chASSERT and chVERIFY Macros\r\nThe chHANDLE_DLGMSG Macro\r\nThe chSETDLGICONS Macro\r\nThe OS Version Check Inline Finctions\r\nMaking Sure the Host System Supports Unicode\r\nForcing the Linker to Look for a(w)WinMain Entry-Point Function\r\n\r\nAPPENDIX B MESSAGE CRACKERS,CHILD CONTROL MACROS,AND API MACROS\r\n\r\nMessage Crackers\r\n\r\nChild Control Macros\r\n\r\nAPI Macros\r\n\r\nIndex