Technical Exchange, DH.
We usually use getlasterror to obtain error information after calling some APIs, but the information is all integer. Do we know what it means?
Hey, yes, there is msdn. Of course, you can also use the formatmessage function.
Let's take a look at the example in the first chapter of Windows core programming and try it with Delphi.
The formatmessage function is mainly used. There are many usage and precautions. You can refer to msdn.
Unit utmain; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, cxgraphics, cxcontrols, controls, containers, cxcontainer, cxedit, dxskinscore, keys, cxgroupbox, cxcheckbox, cxtextedit, audit, cxlabel, menus, cxmemo, stdctrls, cxbuttons; Type tform3 = Class (tform) cxlbl1: tcxlabel; Role: role; cxtxtcode: role; Role: tcxcheckbox; kgdescription: tcxgroupbox; btnsearch: tcxbutton; cxmdescription: pushed; Procedure btnsearchclick (Sender: tobject); Procedure destroy (Sender: tobject); Private {private Declarations} dwcode: Cardinal; systemlocale: cardinal; Public {public declarations} end; var form3: tform3; implementation {$ R *. DFM} procedure tform3.btnsearchclick (Sender: tobject); var B: Cardinal; hlib: Cardinal; Buf: pchar; begin if cxchkhex. checked then dwcode: = strtointdef ('$' + cxtxtcode. text, 0) else dwcode: = strtointdef (cxtxtcode. text, 0); getmem (BUF, 256); try // get B: = formatmessage (format_message_from_system, nil, dwcode, systemlocale, Buf, 255, nil ); // if no network-related if B = 0 then begin hlib: = LoadLibraryEx ('netmsg. dll ', 0, dont_resolve_dll_references); try assert (hlib <> 0); B: = formatmessage (format_message_from_hmodule, pointer (hlib), dwcode, systemlocale, Buf, 255, nil ); finally if hlib <> 0 then freelibrary (hlib); end; If (B <> 0) Then cxmdescription. text: = Buf else cxmdescription. text: = 'the Error Code cannot be found '; finally freemem (BUF); end; Procedure tform3.formcreate (Sender: tobject); begin // set the language to the default systemlocale: = makelangid (lang_neutral, sublang_default) end; end.
for the sake of DX skin, I used the devexpress control but did not use other functions of the control. If Dev is not installed, you can replace them with the most common buttons.
here is an image: