I am trying to use SHFileOperation() to copy a folder, but get this error:
a value of type "const char *" cannot be assigned to an entity of type "PCZZWSTR"
for both s.pTo and s.pFrom.
The code I'm using is:
SHFILEOPSTRUCT s = { 0 };
s.hwnd = hWnd;
s.wFunc = FO_COPY;
s.fFlags = FOF_SILENT;
s.pTo = "C:\\Users\\styler\\Desktop\\Folder1\0";
s.pFrom = "C:\\Users\\styler\\Desktop\\Software\\Folder2\\Folder3\\*\0";
SHFileOperation(&s);
What am I doing wrong in s.pTo and s.pFrom? I am setting those equal to the target folder and the source folder, but why is this not working?
The compiler is telling you that you are trying to assign
charstring literals towchar_tstring pointers (PCZZWSTR=CONST WCHAR *). That means you must be compiling withUNICODEdefined, whereSHFileOperation()maps toSHFileOperationW()which expectswchar_t*string pointers instead ofchar*string pointers.So, you need to prefix your string literals with the
Lprefix, eg:Or, since you are actually using the
TCHARversion ofSHFileOperation(), use theTEXT()macro to match your string literals to the actual character type used byTCHAR: