I call a save dialog to save a xml file (ex: a.xml), then save a clone of it(ex: a_clone.xml) to other location silently. But it only work for a.xml file. This my code for save dialog:
string Savefilename(char *filter = "Mission Files (*.mmf)\0*.mmf", HWND owner = NULL){
OPENFILENAME ofn;
char fileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = "";
ofn.lpstrInitialDir ="Missions\\";
string fileNameStr;
if ( GetSaveFileName(&ofn) )
fileNameStr = fileName;
return fileNameStr;
}
Can anyone help me please!
CopyFile
is a simple function and generally reliable. It fails here probably because target directory does not exit, or because you don't have write access to target directory. It's the same withstd::ofstream myfile
you are probably not checking for errors.Make sure target directory exists. Give the full pathname to destination file. Make sure you have access to target directory.
Note, "c:\program files" etc. are protected directories, you need admin access to copy to these directories.
You can also check for errors: