哪位仁兄用过Windows的Api----Getlasterror函数,介绍介绍吧!(20分)

  • 主题发起人 主题发起人 大海无量
  • 开始时间 开始时间

大海无量

Unregistered / Unconfirmed
GUEST, unregistred user!
如标题所示,多谢了!
 
Pass GetLastError into a call to SysErrorMessage

For Example
Host := gethostbyname('www.delphibbs.com');
error := GetLastError();
if (error <> 0) then
begin
Memo1.SetTextBuf('Error in call to'+ 'gethostbyname().');
Memo1.Lines.Add('Error code: '+IntToStr(error));
Exit;
end;
 
The GetLastError function returns the calling thread's last-error code value.
The last-error code is maintained on a per-thread basis. Multiple threads
do not overwrite each other's last-error code.

DWORD GetLastError(VOID)


Parameters

This function has no parameters.

Return Values

The return value is the calling thread's last-error code value. Functions set
this value by calling the SetLastError function. The Return Value section of
each reference page notes the conditions under which the function sets the
last-error code.

Remarks

You should call the GetLastError function immediately when a function's return
value indicates that such a call will return useful data. That is because some
functions call SetLastError(0) when they succeed, wiping out the error code
set by the most recently failed function.
Most functions in the Win32 API that set the thread's last error code value set
it when they fail; a few functions set it when they succeed. Function failure
is typically indicated by a return value error code such as FALSE, NULL,
0xFFFFFFFF, or -1. Some functions call SetLastError under conditions of
success; those cases are noted in each function's reference page.

Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is
reserved for application-defined error codes; no system error code has this
bit set. If you are defining an error code for your application, set this
bit to one. That indicates that the error code has been defined by an
application, and ensures that your error code does not conflict with any
error codes defined by the operating system.
To obtain an error string for operating system error codes, use the
FormatMessage function. For a complete list of error codes, see the WINNT.H
header file in the Win32 SDK.

See Also

FormatMessage, SetLastError, SetLastErrorEx
 
http://www.undu.com/Articles/000103b.html
 
多人接受答案了。
 
后退
顶部