The fifth day of learning vc ++ - Find and error handling

Today learned a few copy, move function .. processing document, and then the main purpose is to learn error handling, error return value winApi understand, there is vs the "Error Lookup" feature.

 

Courses above https://www.bilibili.com/video/av79302998?p=59  by way of such error checking vs a bit mean ..

In the course of https://www.bilibili.com/video/av79302998?p=60  have to explain, but the processing of two video is on a code, one is on the vs.

 

Tools - Find error, input error value.

Note that this tool if not, vs the control panel to select the top, and then install the relevant content c ++, otherwise only install the net is not ....

There is a tool - Import and export settings - Reset all settings --Visual C ++, C ++ select engineering environment !!

 

 

We must first know winapi error is stored GetLastError (), and then on top of the video call @err monitoring, the search a bit related information, with $ err, hr be monitored.

Specific Description:  https://blog.csdn.net/qq_16334327/article/details/81838300

 

This success can be monitored as video tutorials, like the wrong information ....

 

Learning mess of code:

#if false // delete files 
    bRet = DeleteFile (path);
     IF (bRet) 
    { 
        MessageBox (NULL, _T ( " deleted successfully! " ), _T ( " Tip " ), MB_OK); 
    } 
    the else 
    { 
        DWORD dwError = GetLastError ( ); // in the wrong statement later .. 
        MessageBox (NULL, _T ( " ! delete failed " ), _T ( " Iip " ), MB_OK); 
    } 
#endif  // false 


#if false // copy files
    // Because the C drive permissions issue so the copy is a failure, in order to raise an error
     // bRet = the CopyFile (path, _T ( "C: \\ abc.png"), FALSE); 
    bRet = the CopyFile (path, _T ( " D: \\ Desktop abc.png \\ " ), FALSE);
     IF (bRet) 
    { 
        the MessageBox (NULL, _T ( " copy success! " ), _T ( " the Tip " ), MB_OK); 
    } 
    the else 
    { 
        DWORD the value of dwError the GetLastError = (); // put error statement later .. 
        the MessageBox (NULL, _T ( " ! copy failed " ), _T ( " the Tip " ), MB_OK); 
    }
#endif  // false 


#if false // move the file 
    // bRet = MoveFile (path, _T ( "D: \\ Desktop abc.png \\")); 
    bRet = MoveFile (_T ( " D: \\ Desktop \ \ abc.png " ), _T ( " D: \\ Desktop abc.png \\ " ));
     IF (bRet) 
    { 
        MessageBox (NULL, _T ( " ! successfully moved " ), _T ( " Tip " ), MB_OK ); 
    } 
    the else 
    { 
        DWORD the value of dwError = the GetLastError (); // put back error statement example error handling .. !! 
        IF (the value of dwError == ERROR_FILE_NOT_FOUND) 
        {
            The MessageBox (NULL, _T ( " ! File does not exist " ), _T ( " the Tip " ), MB_OK); 
        } 
        the else 
        { 
            the MessageBox (NULL, _T ( " Failed to move! " ), _T ( " the Tip " ), MB_OK); 
        }   
    } 
#endif  // false
View Code

 

Guess you like

Origin www.cnblogs.com/JJBox/p/12535975.html