Introduction to the getlasterror () function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.