Solved

C++ MovieFile Errorcodes

Posted on 2009-04-08
4
303 Views
Last Modified: 2013-11-20
Hello,
is there a list available of the most happen errors with the movefile function? I want to query the most common errors with a case function to give the user a feedback and with the others, unknown, an message to contact support.

Thanks,

Orana
0
Comment
Question by:Ocrana
4 Comments
 
LVL 1

Expert Comment

by:DaRakNa
ID: 24103039
MoveFile Function
Moves an existing file or a directory, including its children.

Syntax
C++
BOOL WINAPI MoveFile(
  __in  LPCTSTR lpExistingFileName,
  __in  LPCTSTR lpNewFileName
);

Parameters
lpExistingFileName [in]
    The current name of the file or directory on the local computer.
lpNewFileName [in]
    The new name for the file or directory. The new name must not already exist. A new file may be on a different file system or drive. A new directory must be on the same drive.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


GetLastError Function

Retrieves the calling thread's last-error code value. The last-error code is maintained on a per-thread basis. Multiple threads do not overwrite each other's last-error code.

    Visual Basic:  Applications should call err.LastDllError instead of GetLastError.

Syntax
C++
DWORD WINAPI GetLastError(void);

Return Value
The return value is the calling thread's last-error code.

To obtain an error string for system error codes, use the FormatMessage function.

More info:
http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms679360(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms679351(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms680746(VS.85).aspx
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 24103565
There are just three I could think of as the most prominent ones (others should be rare occasions):
//
// MessageId: ERROR_FILE_NOT_FOUND
//
// MessageText:
//
//  The system cannot find the file specified.
//
#define ERROR_FILE_NOT_FOUND             2L
 
//
// MessageId: ERROR_PATH_NOT_FOUND
//
// MessageText:
//
//  The system cannot find the path specified.
//
#define ERROR_PATH_NOT_FOUND             3L
 
//
// MessageId: ERROR_ACCESS_DENIED
//
// MessageText:
//
//  Access is denied.
//
#define ERROR_ACCESS_DENIED              5L

Open in new window

0
 
LVL 4

Expert Comment

by:StefanKittel
ID: 24104654
Hello,

I use this code to the error as normal text.
Exchange MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN) with your language and show the real error so the user can do something.

Stefan
CString returnString = GetLastErrorAsString(GetLastError());
 
 
CString GetLastErrorAsString(DWORD _errorID)
{
	char		GetLastErrorText[1024];
	CString		tempS;
 
	memset(GetLastErrorText, 0x0, sizeof(GetLastErrorText));
 
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, _errorID, MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), GetLastErrorText, 1024, NULL );
 
	tempS = GetLastErrorText;
	tempS.TrimRight();
 
	return tempS;
}

Open in new window

0
 

Author Closing Comment

by:Ocrana
ID: 31568308
Exact what we needed.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question