GetLastError与SetLastError的使用和注意事项

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

你可能感兴趣的:(error)