riviraz
riviraz

Reputation: 479

How to concat LPCWSTR and char[]?

I am trying to concat a LPCWSTR and a char[] (and get LPCWSTR as output).

How can I do that?

Upvotes: 0

Views: 2099

Answers (2)

Osiris76
Osiris76

Reputation: 1244

You could convert your char[] array into a wide-char array using the following code (from MSDN)

wchar_t * wcstring = new wchar_t[strlen(array) + 1];

// Convert char* string to a wchar_t* string.
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, strlen(array) + 1, array, _TRUNCATE);

After that you can use wcscat_s to concatenate the converted character array to your original LPCWSTR.

Upvotes: 1

Marius Bancila
Marius Bancila

Reputation: 16318

You are trying o concatenate a UNICODE string with an ANSI string. This won't work unless you convert the ANSI string to UNICODE. You can use MultiByteToWideChar for that, or ATL and MFC String Conversion Macros if you're using ATL or MFC.

Upvotes: 3

Related Questions