We usually use GetLastError to get the error message after calling some APIs, but the information is integer, do we know what it means?
Hey, yes, there is MSDN Ah, of course, you can also use the FormatMessage function.
Just looked at the Windows core Programming chapter I have an example to use Delphi to try.
Mainly uses the FormatMessage function, the concrete usage and the attention matter is many, everybody may look at MSDN.
Unit utmain;interfaceuses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Cxgraphics, Cxcontrols, Cxlookandfeels, Cxlookandfeelpainters, Cxcontainer, Cxedit, Dxskinscore, DxSkinSeven, Cx GroupBox, Cxcheckbox, Cxtextedit, Dxskinsform, Cxlabel, Menus, Cxmemo, Stdctrls, cxbuttons; Type TFORM3=Class (tform) Cxlbl1:tcxlabel; Dxskincontroller1:tdxskincontroller; Cxtxtcode:tcxtextedit; Cxchkhex:tcxcheckbox; Grpdescription:tcxgroupbox; Btnsearch:tcxbutton; Cxmdescription:tcxmemo; Procedure Btnsearchclick (Sender:tobject); Procedure formcreate (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, the); Try//try to get a bitB: = FormatMessage (Format_message_from_system, Nil, Dwcode, Systemlocale,buf,255, Nil); //If the default is not queried under network-relatedIf B =0Then 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<>0Then FreeLibrary (hlib); End; End; If (B<>0) then Cxmdescription.text:=Buf Else cxmdescription.text:='No description of error code found'; Finally Freemem (BUF); End; End; Procedure tform3.formcreate (Sender:tobject); Begin//set Language as defaultSystemLocale: =makelangid (lang_neutral, Sublang_default) End; End.
http://blog.csdn.net/yanjiaye520/article/details/6694510
GetLastError to get the error message into a text description