GetLastError to get the error message into a text description

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.