Hello,

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.

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;
free(lpwstrSerialNumberW);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.