_wrename in WinApi app.

So i am having bit of a problem. _wrename is not working out for me, and returns bizzare values, instead of 0 (succes) it returns 2 or 22;
Here is part of the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
spec = "\u202E";
exe = ".exe";
oldname2wexe = s2ws(oldname);
oldname = oldname.substr(0, oldname.find(".", 0));
oldname2 = s2ws(oldname);
newname2 = s2ws(newname);
extension2 = s2ws(extension);
spec2 = s2ws(spec);
exe2 = s2ws(exe);
newname2 = oldname2 + spec2 + extension2 + exe2;
rename(sNazwaPliku, newname.c_str());
MessageBoxW(hwnd, oldname2.c_str(), NULL, MB_OK);
if(_wrename(oldname2wexe.c_str(), newname2.c_str()) == 0)
      MessageBox(hwnd, "Sucessfull rename.", "Succes", MB_OK);
else
{
	error = errno;
	stream << error;
	stream >> number;
	MessageBox(hwnd, "Failure", number.c_str(), MB_OK);
}
break;

Here it try to do _wrename, with (as you can see above) i am trying to use unicode right-to-left override, U202E,"\u202E". This causes "Failure" Message box with title either 2 or 22, instead of "succesfull rename" messagebox. However, if i remove "\" from spec, and make the unicode character a simple string, it renames the file, and spawns "Succesfull rename" messagebox.
1
2
3
4
5
6
7
8
9
if(_wrename(oldname2wexe.c_str(), newname2.c_str()) == 0)
		MessageBox(hwnd, "Sucessfull rename.", "Succes", MB_OK);
	else
	{
		error = errno;
		stream << error;
		stream >> number;
		MessageBox(hwnd, "Failure", number.c_str(), MB_OK);
	}


Excuse me if code is not fully readable, but i think it's a simple mistake i made somewhere and i will be really thankfull to someone who will help.

Im short: Why using a unicode "\u202E" in the wstring that is the newname argument in _wrename, causes errors and fails at renaming the file ?


EDIT: Also to clear things up i would like to add that program is supposed to pick a file, remove the ".exe" extension, then insert the override unicode, areversed fileformat that user chooses, and .exe again, which should then display something like "asdfexe.png", since unicode would flip the characters.
Last edited on
> This causes "Failure" Message box with title either 2 or 22, instead of "succesfull rename" messagebox.
http://www.cplusplus.com/reference/cstdio/perror/
or compare `errno' against EACCES, ENOENT, EINVAL
I already did but that does not help. If i compare 2 as secibd if errirs, aka "NOENT" that means that there's no such file as the one im writing. But the moment i remove the "/" from the unicode thing, it works, and instead of right-to-left override, it uses a string "u202E".
Anybody here willing to help ?

EDIT: I compared errno against the errorcodes that ne555 told me to, seems that error is "EINVAL".
Last edited on
Topic archived. No new replies allowed.