GetLastError如何用?

csdnxw 2003-09-18 06:16:30
如题,还没有用过,只知道是返回的一个整数,可是这个整数是干什么的?
...全文
237 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnxw 2003-09-19
  • 打赏
  • 举报
回复
赫赫,好好好。各有千秋,给分!
ccrun.com 2003-09-19
  • 打赏
  • 举报
回复
Edit1->Text=SysErrorMessage(GetLastError());
binbin 2003-09-18
  • 打赏
  • 举报
回复
这是我常用的版本,看来与T头的同宗同源啊,哈哈.

LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
TR@SOE 2003-09-18
  • 打赏
  • 举报
回复
给你一个比较标准的做法吧:

void __fastcall TMainForm::ShowError()
{
char * lpMsgBuf;

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);

// Display the string.
MessageBox( NULL, lpMsgBuf, "系统错误", MB_OK|MB_ICONINFORMATION );

// Free the buffer.
LocalFree( lpMsgBuf );
}
riverking 2003-09-18
  • 打赏
  • 举报
回复
GetLastError
This function returns the calling thread’s last-error code value. A remote application interface (RAPI) version of this function exists, and it is named CeGetLastError.

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧