MoveFile() problems VC++

So I am trying to move a file that the user specifies by using cin and MoveFile(). But the thing is MoveFile() parameters take LPCTSTR variables but cin doesnt take those variable types can anyone help me with a conversion from a char myChars[] table to a LPCTSTR variable?
bump
http://programmers.stackexchange.com/a/194768

Many Microsoft functions come in different flavours depending on the type of characters which are in use.

In order to use a plain C++ character array, use the MoveFileA() variant. This is the same as MoveFile() but operates on ordinary char rather than T‌CHAR.
Last edited on
1
2
3
4
5
6
7
8
9
BOOL CopyTheFile()
{
	DWORD dwResult = MoveFileA("C:\\Users\\username\\Desktop\\test.exe", "C:\\Users\\username\\Desktop\\folder1\\test.exe");
	if (!dwResult)
	{
		return false;
	}
	return true;
}


This was just some pseudo-code which I wrote so a copy paste may not work as I didn't test but try it anyway.
Last edited on
:-(

MoveFileA (and MoveFileW, for that matter) returns a BOOL already, so CopyThisFile is using the wrong return type for the function (and will get a signed/unsigned warning when compiled if you are being good and have cramked up your warning level.)

Also, as I like things to be consistent, you should really use true and false with the C++ bool type, not the archaic typedef (of int) BOOL (which goes with the hash #defines TRUE and FALSE).

1
2
3
4
5
6
7
8
9
10
bool CopyTheFile()
{
	BOOL result = MoveFileA("C:\\Users\\username\\Desktop\\test.exe", 
                                "C:\\Users\\username\\Desktop\\folder1\\test.exe");
	if (!result)
	{
		return false;
	}
	return true;
}
Topic archived. No new replies allowed.