您的位置:首页 > 其它

GetLastError与SetLastError的使用和注意事项

2013-07-27 23:45 363 查看
GetLastError 与 SetLastError

#include <windows.h>
#include <stdio.h>

#define ERROR_NOT_SUPPORTED              50L

int func(int m)
{
if(m == 0 )
//SetLastError(0xe0000001);
SetLastError(ERROR_NOT_SUPPORTED);
else
return true;
return false;

}

void main ()
{
if(!func(0))
printf("%x\n",GetLastError());
else
printf("is true\n");
//system("pause");
Sleep(500000);
}


也许一眼看去,这东东还很好用,但在实际运用中就会有很多问题了。一般它的使用有很大局限性,即是一个函数内部至少一次Set,而每次调用后应馬上Get。不然下次得到的就不一定是你想要的那一次ERROR了,即被告覆盖了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: