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