Introduction to the getlasterror () function
This is a very simple function. Its function is to obtain the error code generated during the previous function operation.
Through the error code, you can find the meaning of each error code in the winerror. h header file. You can also use the error lookup tool that comes with VC ++ to find the meaning indicated by it. The result is the same.
This function is described as follows:
DWORD getlasterror (void );
This is a function without parameters. by calling this function, a 32-bit value is returned.
Below is a simple VC ++ example to illustrate this function.
# Include <windows. h>
Int winapi wwinmain (hinstance,
Hinstance hprevinstance,
Lptstr lpcmdline,
Int ncmdshow)
{
Handle hfile = createfile ("C: // a.txt", 0, 0, null, open_existing, 0, null );
Dword k = getlasterror ();
Return 0;
}
Here, creatfile is a function that creates a file handle for an existing file. If the function is successful, 0 is returned.
We use the K variable to capture the value returned by the getlasterror function.
Then, you can set the breakpoint in the last sentence to intuitively view the value of the variable k.
Then, we create a file named a.txt in C :/.
This is a correct function call, so K is 0;
After "C: // a.txt" is changed to "C:/a.txt", K is 123;
The error lookup tool indicates that the file name, directory name, or volume label syntax is incorrect"
After "C: // a.txt" is changed to "C:/B .txt", K is 2;
The error lookup tool indicates that the system cannot find the specified file"
And so on. There are still many such applications. I will discuss them later.