Win32APIReference Win32 API Reference for HLA 1 Kernel32.lib 1.1 AddAtom TheAddAtomfunctionaddsacharacterstringtothelocalatomtableandreturnsauniquevalue(anatom)identify- ingthestring. AddAtom: procedure ( lpString: string ); stdcall; returns( "eax" ); external( "__imp__AddAtomA@4" ); Parameters lpString [in]Pointertothenull-terminatedstringtobeadded.Thestringcanhaveamaximumsizeof255bytes.Strings differingonlyincaseareconsideredidentical.Thecaseofthefirststringaddedispreservedandreturnedbythe GetAtomNamefunction. Alternatively,youcanuseanintegeratomthathasbeenconvertedusingtheMAKEINTATOMmacro.Seethe Remarksformoreinformation. ReturnValues Ifthefunctionsucceeds,thereturnvalueinEAXisthenewlycreatedatom. Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError. Remarks TheAddAtomfunctionstoresnomorethanonecopyofagivenstringintheatomtable.Ifthestringisalreadyinthe table,thefunctionreturnstheexistingatomand,inthecaseofastringatom,incrementsthestring'sreferencecount. IflpStringhastheform"#1234",AddAtomreturnsanintegeratomwhosevalueisthe16-bitrepresentationofthe decimalnumberspecifiedinthestring(0x04D2,inthisexample).Ifthedecimalvaluespecifiedis0x0000oris greaterthanorequalto0xC000,thereturnvalueiszero,indicatinganerror.IflpStringwascreatedbytheMAKEIN- TATOMmacro,thelow-orderwordmustbeintherange0x0001through0xBFFF.Ifthelow-orderwordisnotin thisrange,thefunctionfails. IflpStringhasanyotherform,AddAtomreturnsastringatom. Requirements WindowsNT/2000:RequiresWindowsNT3.1orlater. Windows95/98:RequiresWindows95orlater. Header:Declaredinkernel32.hhf. Library:UseKernel32.lib. Page1 Volume1 1.2 AllocConsole TheAllocConsolefunctionallocatesanewconsoleforthecallingprocess. AllocConsole: procedure; stdcall; returns( "eax" ); // Zero if failure external( "__imp__AllocConsole@0" ); Parameters Thisfunctionhasnoparameters. ReturnValues Ifthefunctionsucceeds,thereturnvalueinEAXisnonzero. Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError. Remarks Aprocesscanbeassociatedwithonlyoneconsole,sotheAllocConsolefunctionfailsifthecallingprocessalready hasaconsole.AprocesscanusetheFreeConsolefunctiontodetachitselffromitscurrentconsole,andthenitcan callAllocConsoletocreateanewconsole.Ifthecallingprocesscreatesachildprocess,thechildinheritsthenew console. AllocConsolealsosetsupstandardinput,standardoutput,andstandarderrorhandlesforthenewconsole.Thestan- dardinputhandleisahandletotheconsole'sinputbuffer,andthestandardoutputandstandarderrorhandlesarehan- dlestotheconsole'sscreenbuffer.Toretrievethesehandles,usetheGetStdHandlefunction. Thisfunctionisprimarilyusedbygraphicsapplicationstocreateaconsolewindow.Graphicsapplicationsareinitial- izedwithoutaconsole.Consoleapplicationsarenormallyinitializedwithaconsole,unlesstheyarecreatedas detachedprocesses(bycallingtheCreateProcessfunctionwiththeDETACHED_PROCESSflag). Requirements Windows NT/2000: Requires Windows NT3.1 orlater. Windows 95/98:Requires Windows 95 orlater. Header:Declaredin kernel32.hhf Library:UseKernel32.lib. 1.3 AreFileApisANSI TheAreFileApisANSIfunctiondetermineswhetherthefileI/OfunctionsareusingtheANSIorOEMcharacterset codepage.Thisfunctionisusefulfor8-bitconsoleinputandoutputoperations. AreFileApisANSI: procedure; stdcall; returns( "eax" ); // Zero for OEM code page, non-zero for ANSI. external( "__imp__AreFileApisANSI@0" ); Parameters Thisfunctionhasnoparameters. ReturnValues IfthesetoffileI/OfunctionsisusingtheANSIcodepage,thereturnvalueisnonzero. IfthesetoffileI/OfunctionsisusingtheOEMcodepage,thereturnvalueiszero. Remarks TheSetFileApisToOEMfunctioncausesasetoffileI/OfunctionstousetheOEMcodepage.TheSetFileApis- Page2 Win32APIReference ToANSIfunctioncausesthesamesetoffileI/OfunctionstousetheANSIcodepage.UsetheAreFileApisANSI functiontodeterminewhichcodepagethesetoffileI/Ofunctionsiscurrentlyusing.Foradiscussionofthesefunc- tions'usage,pleaserefertotheRemarkssectionsofSetFileApisToOEMandSetFileApisToANSI. ThefileI/OfunctionswhosecodepageisascertainedbyAreFileApisANSIarethosefunctionsexportedby KERNEL32.DLLthatacceptorreturnafilename. ThefunctionsSetFileApisToOEMandSetFileApisToANSIsetthecodepageforaprocess,soAreFileApisANSI returnsavalueindicatingthecodepageofanentireprocess. Requirements Windows NT/2000: Requires Windows NT3.1 orlater. Windows 95/98:Requires Windows 95 orlater. Header: Declaredin kernel32.hhf. Library:UseKernel32.lib. 1.4 AssignProcessToJobObject TheAssignProcessToJobObjectfunctionassociatesaprocesswithanexistingjobobject. AssignProcessToJobObject: procedure ( hJob:dword; hProcess:dword ); stdcall; returns( "eax" ); external( "__imp__AssignProcessToJobObject@8" ); Parameters hJob [in]Handletothejobobjecttowhichtheprocesswillbeassociated.TheCreateJobObjectorOpenJobOb- jectfunctionreturnsthishandle.ThehandlemusthavetheJOB_OBJECT_ASSIGN_PROCESSaccessright associatedwithit.Formoreinformation,seeJobObjectSecurityandAccessRights. hProcess [in]Handletotheprocesstoassociatewiththejobobject.Theprocessmustnotalreadybeassignedtoajob.The handlemusthavePROCESS_SET_QUOTAandPROCESS_TERMINATEaccesstotheprocess.Formore information,seeProcessSecurityandAccessRights. TerminalServices:Allprocesseswithinajobmustrunwithinthesamesession. ReturnValues Ifthefunctionsucceeds,thereturnvalueinEAXisnonzero. Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError. Remarks AfteryouassociateaprocesswithajobobjectusingAssignProcessToJobObject,theprocessissubjecttothelimits setforthejob.Tosetlimitsforajob,usetheSetInformationJobObjectfunction. Ifthejobhasauser-modetimelimit,andthetimelimithasbeenexhausted,AssignProcessToJobObjectfailsand thespecifiedprocessisterminated.Ifthetimelimitwouldbeexceededbyassociatingtheprocess,AssignProcessTo- JobObjectstillsucceeds.However,thetimelimitviolationwillbereported.Ifthejobhasanactiveprocesslimit, andthelimitwouldbeexceededbyassociatingthisprocess,AssignProcessToJobObjectfails,andthespecifiedpro- cessisterminated. Memoryoperationsperformedbyaprocessassociatedwithajobthathasamemorylimitaresubjecttothememory Page3 Volume1 limit.MemoryoperationsperformedbytheprocessbeforeitwasassociatedwiththejobarenotexaminedbyAssign- ProcessToJobObject. Iftheprocessisalreadyrunningandthejobhassecuritylimitations,AssignProcessToJobObjectmayfail.For example,iftheprimarytokenoftheprocesscontainsthelocaladministratorsgroup,butthejobobjecthasthesecu- ritylimitationJOB_OBJECT_SECURITY_NO_ADMIN,thefunctionfails.Ifthejobhasthesecuritylimitation JOB_OBJECT_SECURITY_ONLY_TOKEN,theprocessmustbecreatedsuspended.Tocreateasuspendedprocess, calltheCreateProcessfunctionwiththeCREATE_SUSPENDEDflag. Aprocesscanbeassociatedonlywithasinglejob.Aprocessinheritslimitsfromthejobitisassociatedwithand addsitsaccountinginformationtothejob.Ifaprocessisassociatedwithajob,allprocessesitcreatesareassociated withthatjobbydefault.Tocreateaprocessthatisnotpartofthesamejob,calltheCreateProcessfunctionwith theCREATE_BREAKAWAY_FROM_JOBflag. Requirements Windows NT/2000: Requires Windows 2000orlater. Windows 95/98:Unsupported. Header: Declaredin kernel32.hhf Library:UseKernel32.lib. 1.5 BackupRead TheBackupReadfunctionreadsdataassociatedwithaspecifiedfileordirectoryintoabuffer.Youusethisfunction tobackupafileordirectory. BackupRead: procedure ( hFile: dword; var lpBuffer: var; nNumberOfBytesToRead: dword; var lpNumberOfBytesRead: dword; bAbort: boolean; bProcessSecurity: boolean; var lpContext: var ); stdcall; returns( "eax" ); external( "__imp__BackupRead@28" ); Parameters hFile [in]Handletothefileordirectorybeingbackedup.Thefunctionreadsdataassociatedwiththisfile.Youobtain thishandlebycallingtheCreateFilefunction. TheBackupReadfunctionfailsifCreateFilewascalledwiththeflagFILE_FLAG_NO_BUFFERING.Inthis case,theGetLastErrorfunctionreturnsthevalueERROR_INVALID_PARAMETER. lpBuffer [out]Pointertoabufferthatthefunctionwritesdatato. nNumberOfBytesToRead [in]Specifiesthelengthofthebuffer.ThebuffersizemustbegreaterthanthesizeofaWIN32_STREAM_ID structure. lpNumberOfBytesRead Page4 Win32APIReference [out]Pointertoavariablethatreceivesthenumberofbytesread. Ifthefunctionreturnsanonzerovalue,andthevariablepointedtobylpNumberOfBytesReadiszero,thenallthe dataassociatedwiththefilehandlehasbeenread. bAbort [in]IndicateswhetheryouhavefinishedusingBackupReadonthehandle.Whileyouarebackingupthefile, specifythisparameterasFALSE.OnceyouaredoneusingBackupRead,youmustcallBackupReadonemore timespecifyingTRUEforthisparameterandpassingtheappropriatelpContext.lpContextmustbepassedwhen bAbortisTRUE;allotherparametersareignored. bProcessSecurity [in]Indicateswhetherthefunctionwillrestoretheaccess-controllist(ACL)dataforthefileordirectory. IfbProcessSecurityisTRUE,theACLdatawillbebackedup. lpContext [out]PointertoavariablethatreceivesandholdsapointertoaninternaldatastructureusedbyBackupReadto maintaincontextinformationduringabackupoperation. YoumustsetthevariablepointedtobylpContexttoNULLbeforethefirstcalltoBackupReadforthespecified fileordirectory.Thefunctionallocatesmemoryforthedatastructure,andthensetsthevariabletopointtothat structure.YoumustnotchangelpContextorthevariablethatitpointstobetweencallstoBackupRead. Toreleasethememoryusedbythedatastructure,callBackupReadwiththebAbortparametersettoTRUE whenthebackupoperationiscomplete. ReturnValues Ifthefunctionsucceeds,thereturnvalueisnonzero. Ifthefunctionfails,thereturnvalueiszero,indicatingthatanI/Oerroroccurred.Togetextendederrorinformation, callGetLastError. Remarks BackupReadprocessesallofthedatapertainingtoanopenedobjectasaseriesofdiscretebytestreams.Eachstream isprecededbya32-bitalignedWIN32_STREAM_IDstructure. Streamsmustbeprocessedinthesameorderinwhichtheywerewrittentothetape.Thisorderingenablesapplica- tionstocomparethedatabackedupagainstthedataonthesourcedevice.ThedatareturnedbyBackupReadistobe usedonlyasinputtotheBackupWritefunction.Thisdataisreturnedasonelargedatastreamdividedintosub- streams.ThesubstreamsareseparatedbyWIN32_STREAM_IDheaders. IfanerroroccurswhileBackupReadisreading,thecallingprocesscanskipthebaddatabycallingtheBackupSeek function. Requirements Windows NT/2000: Requires Windows NT3.1 orlater. Header: Declaredin kernel32.hhf Library:UseKernel32.lib. 1.6 BackupSeek TheBackupSeekfunctionseeksforwardinadatastreaminitiallyaccessedbyusingtheBackupReadorBackup- Writefunction. BackupSeek: procedure ( hFile: dword; dwLowBytesToSeek: dword; dwHighBytesToSeek: dword; Page5 Volume1 var lpdwLowByteSeeked: dword; var lpdwHighByteSeeked: dword; var lpContext: dword ); stdcall; returns( "eax" ); external( "__imp__BackupSeek@24" ); Parameters hFile [in]Handletothefileordirectorybeingbackedup.ThishandleiscreatedbyusingtheCreateFilefunction. dwLowBytesToSeek [in]Specifiesthelow-orderbitsofthenumberofbytestoseek. dwHighBytesToSeek [in]Specifiesthehigh-orderbitsofthenumberofbytestoseek. lpdwLowByteSeeked [out]Pointertoavariablethatreceivesthelow-orderbitsofthenumberofbytesthefunctionactuallyseeks. lpdwHighByteSeeked [out]Pointertoavariablethatreceivesthehigh-orderbitsofthenumberofbytesthefunctionactuallyseeks. lpContext [in]Pointertoaninternaldatastructureusedbythefunction.Thisstructuremustbethesamestructurethatwas initializedbytheBackupReadfunction.Anapplicationmustnottouchthecontentsofthisstructure. ReturnValues Ifthefunctioncouldseektherequestedamount,thefunctionreturnsanonzerovalue. Ifthefunctioncouldnotseektherequestedamount,thefunctionreturnszero.Togetextendederrorinformation,call GetLastError. Remarks ApplicationsusetheBackUpSeekfunctiontoskipportionsofadatastreamthatcauseerrors.Thisfunctiondoesnot seekacrossstreamheaders.Ifanapplicationattemptstoseekpasttheendofasubstream,thefunctionfails,thelpd- wLowByteSeekedandlpdwHighByteSeekedparametersindicatetheactualnumberofbytesthefunctionseeks,and thefilepositionisplacedatthestartofthenextstreamheader. Requirements WindowsNT/2000:RequiresWindowsNT3.1orlater. Header:DeclaredinWinbase.h;includeWindows.h. Library:UseKernel32.lib. SeeAlso Tape Backup Overview,Tape Backup Functions,BackupRead,BackupWrite,CreateFile 1.7 BackupWrite TheBackupWritefunctionwritesastreamofdatafromabuffertoaspecifiedfileordirectory.Thedatamustbe dividedintosubstreamsseparatedbyWIN32_STREAM_IDstructures.Youusethisfunctiontorestoreafileordirec- torythathasbeenbackedup. BackupWrite: procedure Page6 Win32APIReference ( hFile: dword; var lpBuffer: var; nNumberOfBytesToWrite: dword; var lpNumberOfBytesWritten: dword; bAbort: boolean; bProcessSecurity: boolean; var lpContext: var ); stdcall; returns( "eax" ); external( "__imp__BackupWrite@28" ); Parameters hFile [in]Handletothefileordirectorybeingrestored.Thefunctionwritesdatatothisfile.Youobtainthishandleby callingtheCreateFilefunction. TheBackupWritefunctionfailsifCreateFilewascalledwiththeflagFILE_FLAG_NO_BUFFERING.Inthis case,theGetLastErrorfunctionreturnsthevalueERROR_INVALID_PARAMETER. lpBuffer [in]Pointertoabufferthatthefunctionwritesdatafrom. nNumberOfBytesToWrite [in]Specifiesthelengthofthebuffer.ThebuffersizemustbegreaterthanthesizeofaWIN32_STREAM_ID structure. lpNumberOfBytesWritten [out]Pointertoavariablethatreceivesthenumberofbyteswritten. bAbort [in]IndicateswhetheryouhavefinishedusingBackupWriteonthehandle.Whileyouarebackingupthefile, specifythisparameterasFALSE.AfteryouaredoneusingBackupWrite,youmustcallBackupWriteone moretimespecifyingTRUEforthisparameterandpassingtheappropriatelpContext.lpContextmustbepassed whenbAbortisTRUE;allotherparametersareignored. bProcessSecurity [in]Specifieswhetherthefunctionwillrestoretheaccess-controllist(ACL)dataforthefileordirectory. IfbProcessSecurityisTRUE,youneedtohavespecifiedWRITE_OWNERandWRITE_DACaccesswhen openingthefileordirectoryhandle.Ifthehandledoesnothavethoseaccessrights,theoperatingsystemdenies accesstotheACLdata,andACLdatarestorationwillnotoccur. lpContext [out]PointertoavariablethatreceivesapointertoaninternaldatastructureusedbyBackupWritetomaintain contextinformationduringarestoreoperation. YoumustsetthevariablepointedtobylpContexttoNULLbeforethefirstcalltoBackupWriteforthespecified fileordirectory.Thefunctionallocatesmemoryforthedatastructure,andthensetsthevariabletopointtothat structure.YoumustnotchangelpContextorthevariablethatitpointstobetweencallstoBackupWrite. Toreleasethememoryusedbythedatastructure,callBackupWritewiththebAbortparametersettoTRUE whentherestoreoperationiscomplete. ReturnValues Ifthefunctionsucceeds,thereturnvalueisnonzero. Page7 Volume1 Ifthefunctionfails,thereturnvalueiszero,indicatingthatanI/Oerroroccurred.Togetextendederrorinformation, callGetLastError. Remarks TheBACKUP_LINKstreamtypeletsyourestorefileswithhardlinks. DataobtainedbytheBackupReadfunctionshouldonlybeusedasinputtotheBackupWritefunction. Requirements WindowsNT/2000:RequiresWindowsNT3.1orlater. Header:DeclaredinWinbase.h;includeWindows.h. Library:UseKernel32.lib. SeeAlso Tape Backup Overview,Tape Backup Functions,BackupRead,BackupSeek,CreateFile, WIN32_STREAM_ID 1.8 Beep TheBeepfunctiongeneratessimpletonesonthespeaker.Thefunctionissynchronous;itdoesnotreturncontroltoits calleruntilthesoundfinishes. Beep: procedure ( dwFreq: dword; dwDuration: dword ); stdcall; returns( "eax" ); external( "__imp__Beep@8" ); Parameters dwFreq Windows NT/2000:[in]Specifies the frequency,inhertz,ofthe sound.This parameter mustbe inthe range37 through 32,767 (0x25 through 0x7FFF). dwDuration Windows NT/2000:[in]Specifies the duration,inmilliseconds,ofthesound. ReturnValues Ifthefunctionsucceeds,thereturnvalueinEAXisnonzero. Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError. Remarks Windows95:TheBeepfunctionignoresthedwFreqanddwDurationparameters.Oncomputerswithasoundcard, thefunctionplaysthedefaultsoundevent.Oncomputerswithoutasoundcard,thefunctionplaysthestandardsystem beep. Requirements WindowsNT/2000:RequiresWindowsNT3.1orlater. Windows95/98:RequiresWindows95orlater. Header:Declaredinkernel32.hhf Library:UseKernel32.lib. Page8 Win32APIReference SeeAlso ErrorHandlingOverview,ErrorHandlingFunctions,MessageBeep 1.9 BeginUpdateResource TheBeginUpdateResourcefunctionreturnsahandlethatcanbeusedbytheUpdateResourcefunctiontoadd, delete,orreplaceresourcesinanexecutablefile. BeginUpdateResource: procedure ( filename: string; bDeleteExistingResources: boolean ); stdcall; returns( "eax" ); external( "__imp__BeginUpdateResourceA@8" ); Parameters pFileName [in]Pointertoanull-terminatedstringthatspecifiestheexecutablefileinwhichtoupdateresources.Anapplica- tionmustbeabletoobtainwriteaccesstothisfile;itcannotbecurrentlyexecuting.IfpFileNamedoesnotspec- ifyafullpath,thesystemsearchesforthefileinthecurrentdirectory. bDeleteExistingResources [in]SpecifieswhethertodeletethepFileNameparameter'sexistingresources.IfthisparameterisTRUE,exist- ingresourcesaredeletedandtheupdatedexecutablefileincludesonlyresourcesaddedwiththeUpdateRe- sourcefunction.IfthisparameterisFALSE,theupdatedexecutablefileincludesexistingresourcesunlessthey areexplicitlydeletedorreplacedbyusingUpdateResource. ReturnValues Ifthefunctionsucceeds,thereturnvalueinEAXisahandlethatcanbeusedbytheUpdateResourceandEndUpda- teResourcefunctions.ThereturnvalueisNULLifthespecifiedfileisnotanexecutablefile,theexecutablefileis alreadyloaded,thefiledoesnotexist,orthefilecannotbeopenedforwriting.Togetextendederrorinformation,call GetLastError. Requirements WindowsNT/2000:RequiresWindowsNT3.1orlater. Windows95/98:Unsupported. Header:Declaredinkernel32.hhf Library:UseKernel32.lib. SeeAlso Resources Overview,Resource Functions,EndUpdateResource,UpdateResource 1.10 BuildCommDCB TheBuildCommDCBfunctionfillsaspecifiedDCBstructurewithvaluesspecifiedinadevice-controlstring.The device-controlstringusesthesyntaxofthemodecommand. BuildCommDCB: procedure ( lpDef: string; var lpDCB: DCB Page9 Volume1 ); stdcall; returns( "eax" ); external( "__imp__BuildCommDCBA@8" ); Parameters lpDef [in]Pointertoanull-terminatedstringthatspecifiesdevice-controlinformation.Thestringmusthavethesame formasthemodecommand'scommand-linearguments.Forexample,thefollowingstringspecifiesabaudrate of1200,noparity,8databits,and1stopbit: baud=1200 parity=N data=8 stop=1 Thedevicenameisignoredifitisincludedinthestring,butitmustspecifyavaliddevice,asfollows: COM1: baud=1200 parity=N data=8 stop=1 Forfurtherinformationonmodecommandsyntax,refertotheend-userdocumentationforyouroperatingsys- tem. lpDCB [out]PointertoaDCBstructurethatreceivestheinformation. ReturnValues Ifthefunctionsucceeds,thereturnvalueisnonzero. Ifthefunctionfails,thereturnvalueiszero.Togetextendederrorinformation,callGetLastError. Remarks TheBuildCommDCBfunctionadjustsonlythosemembersoftheDCBstructurethatarespecificallyaffectedbythe lpDefparameter,withthefollowingexceptions: Ifthespecifiedbaudrateis110,thefunctionsetsthestopbitsto2toremaincompatiblewiththe system'smodecommand. Bydefault,BuildCommDCBdisablesXON/XOFFandhardwareflowcontrol.Toenableflow control,youmustexplicitlysettheappropriatemembersoftheDCBstructure. TheBuildCommDCBfunctiononlyfillsinthemembersoftheDCBstructure.Toapplythesesettingstoaserial port,usetheSetCommStatefunction. Thereareolderandnewerformsofthemodecommandsyntax.TheBuildCommDCBfunctionsupportsbothforms. However,youcannotmixthetwoformstogether. Thenewerformofthemodecommandsyntaxletsyouexplicitlysetthevaluesoftheflowcontrolmembersofthe DCBstructure.Ifyouuseanolderformofthemodesyntax,theBuildCommDCBfunctionsetstheflowcontrol membersoftheDCBstructure,asfollows: Forastringsuchas96,n,8,1oranyotherolder-formmodestringthatdoesn'tendwithanxorap: fInX,fOutX,fOutXDsrFlow,andfOutXCtsFlowareallsettoFALSE fDtrControlissettoDTR_CONTROL_ENABLE fRtsControlissettoRTS_CONTROL_ENABLE Forastringsuchas96,n,8,1,xoranyotherolder-formmodestringthatendswithanx: fInXandfOutXarebothsettoTRUE fOutXDsrFlowandfOutXCtsFlowarebothsettoFALSE fDtrControlissettoDTR_CONTROL_ENABLE fRtsControlissettoRTS_CONTROL_ENABLE Forastringsuchas96,n,8,1,poranyotherolder-formmodestringthatendswithap: fInXandfOutXarebothsettoFALSE Page10
Description: