I'm trying to use a string (filepath) with the windows IFileOperation interface.
Only, the CopyItem method calls for the filepath as a PCWSTR.

I've been googling and trying different things for half an hour but for the life of me I can't find out how to convert this string. I can barely find anything on the net mentioning PCWSTR. Apparently it's a WCHAR*?

I'm using Multibyte, not Unicode - if that makes a difference.

Hopefully someone can shed some light on this.
In the meantime, I'm still looking, thanks.

8 Years
Discussion Span
Last Post by Ketsuekiame

You need to convert from MultiByte to WideChar. Before doing that though, see if there is a CopyItemA method. The A reverts back to the non-Unicode form of the method (and exists for a lot of Microsoft methods)

Otherwise, here's some example code.

wstringstream sstr;
configFile >> serialNumber;
size_t numberOfCharsConverted = 0;
size_t originalLength = strlen(serialNumber.c_str()) + 1;
TCHAR* lpwstrSerialNumberW = (TCHAR*)malloc(sizeof(TCHAR) * originalLength);
mbstowcs_s(&numberOfCharsConverted, lpwstrSerialNumberW, originalLength, serialNumber.c_str(), _TRUNCATE);
serialNumberW = lpwstrSerialNumberW;

Some people will use MultiByteToWideChar but I've had problems with this method adding nonsense characters onto the end of Strings.

Edited by Ketsuekiame: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.