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了,即被告覆盖了。

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2021-10-05
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案