[散分][关于GetLastError的问题]

柯本 2006-04-27 08:22:56
今天在编译fport的源码时(原在VC下的)老是报内存错,经检查原来是由于BCB返回不正确的GetLastError所致,郁闷之余,作了一个测试,新建项目,加一按钮
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ShowMessage(SysErrorMessage(GetLastError()));
}
居然显示:窗口没有滚动条.
不知大家有无类似问题,来者有分
...全文
304 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
柯本 2006-05-01
  • 打赏
  • 举报
回复
感谢各位参与,祝大家五.一快乐!
caizhen2000_82 2006-04-30
  • 打赏
  • 举报
回复
jf
pp616 2006-04-30
  • 打赏
  • 举报
回复
先SetLastError(0);
再调功能代码。
然后GetLastError();
ccrun.com 2006-04-30
  • 打赏
  • 举报
回复
很多API本身的返回值就可以表示函数执行成功与否,单纯的靠GetLastError有失误的。
柯本 2006-04-29
  • 打赏
  • 举报
回复
继续...
jone7319 2006-04-28
  • 打赏
  • 举报
回复
没见过
kwokwinglau 2006-04-28
  • 打赏
  • 举报
回复
路过接分。
scjpsz1860 2006-04-28
  • 打赏
  • 举报
回复
快乐接分!:)
柯本 2006-04-28
  • 打赏
  • 举报
回复
我也明白cczlp(不惑)所说,问题是我是在函数后直接用的,如下:
...
hMemory = MapViewOfFile(hSection, FILE_MAP_READ,
0, 0x30000, 0x1000);
if (GetLastError() != 0) return NULL;
...
GetLastError()返回为127(找不到指定程序),而同样的代码在VC下没问题
我只能改成
if (hMemory==NULL) return NULL;
没问题
wangxintu 2006-04-28
  • 打赏
  • 举报
回复
我的显示“操作成功完成”
netsys2 2006-04-28
  • 打赏
  • 举报
回复
8错
daydayup234 2006-04-28
  • 打赏
  • 举报
回复
only 接分
BlueDeepOcean 2006-04-28
  • 打赏
  • 举报
回复
学习,同时关注,并且继续往上顶!
tianshu888 2006-04-28
  • 打赏
  • 举报
回复
接分了
ccrun.com 2006-04-28
  • 打赏
  • 举报
回复
同意cczlp
rudolf_he 2006-04-28
  • 打赏
  • 举报
回复
学习
cczlp 2006-04-28
  • 打赏
  • 举报
回复
应该在一个API之后紧接着调用GetLastError, BCB的函数已经执行了N个API,
GetLastError返回的已经不是你要的了。
wmlalison 2006-04-28
  • 打赏
  • 举报
回复
接分 ^_^
土著巫师 2006-04-27
  • 打赏
  • 举报
回复
1、The GetLastError function retrieves 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.

2、Most functions 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 zero, NULL, or –1. Some functions call SetLastError under conditions of success; those cases are noted in each function's reference page.

3、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 with a zero when they succeed, wiping out the error code set by the most recently failed function.

老之 2006-04-27
  • 打赏
  • 举报
回复
:)
加载更多回复(1)

552

社区成员

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

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