Table Of ContentY
L
F
M
A
E
T
Team-Fly®
The Tomes of Delphi™
Win32 Core API
Windows 2000 Edition
John Ayres
Wordware Publishing, Inc.
LibraryofCongressCataloging-in-PublicationData
Ayres,John.
TomesofDelphi: Win32CoreAPIWindows2000edition / byJohnAyres.
p. cm.
Includesbibliographicalreferencesandindex.
ISBN 1-55622-750-7(pbk.)
1. MicrosoftWin32. 2. Delphi(Computerfile). I. Title.
QA76.76.O63A97 2001 2001046842
005.265--dc21 CIP
Copyright©2002,WordwarePublishing,Inc.
AllRightsReserved
2320LosRiosBoulevard
Plano,Texas75074
Nopartofthisbookmaybereproducedinanyformorby
anymeanswithoutpermissioninwritingfrom
WordwarePublishing,Inc.
PrintedintheUnitedStatesofAmerica
ISBN1-55622-750-7
10 9 8 7 6 5 4 3 2 1
0110
DelphiisatrademarkofBorlandSoftwareCorporationintheUnitedStatesandothercountries.
WindowsisaregisteredtrademarkofMicrosoftCorporationintheUnitedStatesand/orothercountries.
Otherproductnamesmentionedareusedforidentificationpurposesonlyandmaybetrademarksoftheirrespectivecompanies.
AllinquiriesforvolumepurchasesofthisbookshouldbeaddressedtoWordwarePublishing,Inc.,attheabove
address.Telephoneinquiriesmaybemadebycalling:
(972)423-0090
Praise for
The Tomes of Delphi 3: Win32 Core API
“TheTomesofDelphiisthedefinitivereferencefortheWin32APIexpressedinthe
ObjectPascallanguage.It’samust-haveforapplicationandcomponentdeveloperslook-
ingtoextendtheirreachbeyondthecapabilitiesoftheVisualComponentLibrary.”
SteveTeixeira,DirectorCoreTechnology
ZoneLabs,Inc.andco-authorofDelphi6Developer’sGuide
***************************
“TheTomesofDelphi3:Win32CoreAPIisanexcellentresourceforDelphiprogrammers
needingtogobeyonddraganddropdevelopment.ThisbooknotonlydiscussestheAPIin
depth,butalsoprovidessolidexamplesofusingDelphitoaccessthepowerofWindows
providedthroughtheAPI.”
XavierPacheco,PresidentandCEO
XapwareTechnologies,Incandco-authorofthebest-selling
Delphi6Developer’sGuide
***************************
“OneofthefeaturesIlikedmostwhenIfirstapproachedDelphiwasitspowertogodown
totheWindowsAPI-level,somethingmostothervisualtoolsstilllack.Butthisisnotan
easytask,andnobooklikeTheTomesofDelphi3:Win32CoreAPIcanhelpyouunder-
standWindowsfromtheDelphiperspective.”
MarcoCantu,authorofthebest-sellingMasteringDelphi6
***************************
“Delphiletsdeveloperswork‘underthehood’withtheWin32API.TheTomesof
Delphi3:Win32CoreAPIgiveseveryDelphidevelopertheknowledgetousetheWin32
APIpowerfully,creatively,andeffectively.”
MichaelSwindell,DirectorofProductManagement
RADToolsGroup,BorlandSoftwareCorporation
***************************
“TheTomesofDelphi3:Win32CoreAPIismynumberoneresourcewhenlookingfor
informationabouthowtousetheWin32coreAPIinDelphi.Iespeciallyenjoythe
helpfilethatcontainsthecompletetextfromthebookandcanbeaccesseddirectlywhen
programming.”
BobSwart(a.k.a.“Dr.Bob”),Author,trainer,consultant
***************************
“NotonlywerethesethefirstDelphibookstoconcentrateonAPI-levelprogramming,
theysetthestandardforallfutureDelphiAPIbooks.”
AlanC.Moore,ContributingEditor
DelphiInformantMagazine
Dedication
Iwouldliketodedicatethisbooktothefollowingpeopleand/ordeitieswhohavehada
profoundinfluenceinmylife:First,toGod,whomI’vebeengrowingmuchcloserto
theselastfewyears,forgivingmetheintelligencetowadethroughtheconfusingand
sometimesmaddeningseaofWindowsAPIdocumentationandmakesenseofitall;sec-
ond,tomyfamily,forputtingupwithmylackofparticipationinfamilyactivitiesduring
thisproject;andfinally,butmostofall,tomywifeandsoulmate,Marci,whomadesureI
hadclothestowearinthemorningandfoodintheevening,fixedmylunches,andgener-
allytookupallofmyhouseworkresponsibilitiessoIcouldconcentrateonthebook.She
encouragedmeandproddedmealongwhentheweightofthisprojectbecameunbearable,
andbecauseofthissheisdirectlyresponsibleforthisworkbeingcompleted.Sheisavery
inspiringtaskmaster;crackingthewhiptobringmeinlinewhenIwouldhaveratherbeen
playingX-Wingvs.TieFighter.Iamunworthyofsuchadevotedandlovingwife,andI
thankGodeverydayforprovidingmewithsuchaperfectcompanion.Baby,thisone’s
foryou.
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Chapter1 DelphiandtheWindowsAPI . . . . . . . . . . . . . . . . . . . . . . . . . 1
WindowsDataTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ImportingWindowsFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
IncorrectlyImportedFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . 5
CallbackFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
FunctionParameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Delphivs.theWindowsAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Chapter2 WindowCreationFunctions . . . . . . . . . . . . . . . . . . . . . . . . . 9
CreatingWindows:TheBasicSteps . . . . . . . . . . . . . . . . . . . . . . . . . 9
WindowAttributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
TheWindowProcedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
HardcoreWindowsProgramming. . . . . . . . . . . . . . . . . . . . . . . . . . 13
WindowTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
MultipleDocumentInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ExtendingFunctionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
WindowCreationandRegistrationFunctions . . . . . . . . . . . . . . . . . . . 26
CreateMDIWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CreateWindowEx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
DestroyWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
MessageBox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
RegisterClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
RegisterClassEx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
UnregisterClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Chapter3 MessageProcessingFunctions. . . . . . . . . . . . . . . . . . . . . . . . 57
TheMessageQueueandMessageLoop . . . . . . . . . . . . . . . . . . . . . . 57
WindowsHooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
InterprocessCommunication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
MessageProcessingFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
v
vi (cid:1)
Contents
BroadcastSystemMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . 63
CallNextHookEx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
CallWindowProc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
DefFrameProc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
DefMDIChildProc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
DefWindowProc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
DispatchMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
GetMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
GetMessageExtraInfo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
GetMessagePos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
GetMessageTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
GetQueueStatus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
InSendMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
PeekMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
PostMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
PostQuitMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
PostThreadMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
RegisterWindowMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ReplyMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
SendMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
SendMessageCallback . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
SendMessageTimeout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
SendNotifyMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
SetMessageExtraInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
SetWindowsHookEx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
WH_CALLWNDPROCHookFunction . . . . . . . . . . . . . . . . . . 105
WH_CALLWNDPROCRETHookFunction . . . . . . . . . . . . . . . . 106
WH_CBTHookFunction . . . . . . . . . . . . . . . . . . . . . . . . . . 107
WH_DEBUGHookFunction . . . . . . . . . . . . . . . . . . . . . . . . 110
WH_FOREGROUNDIDLEHookFunction . . . . . . . . . . . . . . . . 111
WH_GETMESSAGEHookFunction. . . . . . . . . . . . . . . . . . . . 111
WH_JOURNALPLAYBACKHookFunction . . . . . . . . . . . . . . . 112
WH_JOURNALRECORDHookFunction . . . . . . . . . . . . . . . . . 114
WH_KEYBOARDHookFunction . . . . . . . . . . . . . . . . . . . . . 115
WH_MOUSEHookFunction . . . . . . . . . . . . . . . . . . . . . . . . 116
WH_MSGFILTERHookFunction . . . . . . . . . . . . . . . . . . . . . 117
WH_SHELLHookFunction . . . . . . . . . . . . . . . . . . . . . . . . 118
WH_SYSMSGFILTERHookFunction. . . . . . . . . . . . . . . . . . . 120
TranslateMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
UnhookWindowsHookEx . . . . . . . . . . . . . . . . . . . . . . . . . . 123
WaitMessage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Chapter4 MemoryManagementFunctions. . . . . . . . . . . . . . . . . . . . . . 125
TheWin32VirtualMemoryArchitecture . . . . . . . . . . . . . . . . . . . . . 125
CategoriesofMemoryAllocationFunctions . . . . . . . . . . . . . . . . . . . 126
Heaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
The16-BitMemoryFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . . 127
VirtualMemory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
(cid:1) vii
Contents
ThreeStatesofMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
HowMuchMemoryisReallyThere? . . . . . . . . . . . . . . . . . . . . . . . 128
MultipleHeaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
ErrorTrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
ThreadAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
MemoryManagementFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . 131
CopyMemory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
FillMemory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
GetProcessHeap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
GlobalAlloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
GlobalDiscard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
GlobalFlags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
GlobalFree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
GlobalHandle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
GlobalLock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
GlobalMemoryStatus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
GlobalReAlloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
GlobalSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
GlobalUnlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
HeapAlloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
HeapCreate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
HeapDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
HeapFree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
HeapReAlloc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
HeapSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
IsBadCodePtr. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
IsBadReadPtr. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
IsBadStringPtr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
IsBadWritePtr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
MoveMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
VirtualAlloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
VirtualFree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
VirtualProtect. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
VirtualQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
ZeroMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Chapter5 Dynamic-LinkLibraryFunctions . . . . . . . . . . . . . . . . . . . . . . 169
Importing/ExportingFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . 169
CallingConventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
TheDynamic-LinkLibraryEntryPointFunction. . . . . . . . . . . . . . . 170
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Dynamic-LinkLibraryFunctions . . . . . . . . . . . . . . . . . . . . . . . . . 171
DLLMain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
DisableThreadLibraryCalls . . . . . . . . . . . . . . . . . . . . . . . . . . 172
FreeLibrary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
FreeLibraryAndExitThread . . . . . . . . . . . . . . . . . . . . . . . . . . 174
viii (cid:1)
Contents
GetModuleFileName . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
GetModuleHandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
GetProcAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
LoadLibrary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
LoadLibraryEx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Chapter6 ProcessandThreadFunctions . . . . . . . . . . . . . . . . . . . . . . . 187
ImportantConcepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
PriorityLevels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
SynchronizationandCoordination. . . . . . . . . . . . . . . . . . . . . . . . . 188
Deadlocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
SynchronizationObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
CriticalSections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Mutexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
SynchronizingProcesseswithaMutex . . . . . . . . . . . . . . . . . . . . 191
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
ProcessandThreadFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
CreateEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
CreateMutex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
CreateProcess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
CreateSemaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
CreateThread. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
DeleteCriticalSection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
DuplicateHandle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
EnterCriticalSection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
ExitProcess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
ExitThread. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
GetCurrentProcess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
GetCurrentProcessId. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
GetCurrentThread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
GetCurrentThreadId . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
GetExitCodeProcess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
GetExitCodeThread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
GetPriorityClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
GetThreadPriority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
GetWindowThreadProcessId . . . . . . . . . . . . . . . . . . . . . . . . 225
InitializeCriticalSection . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
InterlockedDecrement. . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
InterlockedExchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
InterlockedIncrement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
LeaveCriticalSection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
OpenEvent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
OpenMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
OpenProcess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
(cid:1) ix
Contents
OpenSemaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
PulseEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
ReleaseMutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
ReleaseSemaphore. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
ResetEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
ResumeThread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
SetEvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
SetPriorityClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
SetThreadPriority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
SuspendThread. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
TerminateProcess. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
TerminateThread. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
TlsAlloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
TlsFree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
TlsGetValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
TlsSetValue. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
WaitForInputIdle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
WaitForSingleObject. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Chapter7 TimerFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
EmulatingaTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
PreciseTiming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
TimerFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
GetTickCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
KillTimer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
QueryPerformanceCounter. . . . . . . . . . . . . . . . . . . . . . . . . . . 262
QueryPerformanceFrequency . . . . . . . . . . . . . . . . . . . . . . . . . 263
SetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Chapter8 ErrorFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
ErrorDescriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
AudibleErrorCues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Delphivs.theWindowsAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
ErrorFunctions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Beep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
ExitWindows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
ExitWindowsEx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
FatalAppExit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
GetLastError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
MessageBeep. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
SetLastError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Chapter9 GraphicalDeviceInterfaceFunctions . . . . . . . . . . . . . . . . . . . 279
DeviceIndependence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
DeviceContexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
DeviceContextTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Screen,Window,andClientAreaDeviceContexts. . . . . . . . . . . . . . 282
Description:The Tomes of Delphi series from John Ayres is recognized as the definitive reference for Delphi programmers and developers. The first edition received rave reviews from industry publications as well as Inprice developers as being the Rosetta stone which forms the link between Delphi and the Windows