Cannot convert from 'WCHAR' to 'WCHAR [260]'

I am trying to modify amcap app from Windows SDK app to capture video from a UVC webcam at 1600x1200px resolution.

I am trying to copy some variables here like filename, default resolution, format type, etc.

WCHAR wszCaptureFile[260]; 

gcap.wszCaptureFile = (WCHAR)"Capture.avi\0"    //modified 

      

Gettnig error:

1>. \ Amcap.cpp (3887): error C2440: '=': unable to convert from 'WCHAR' to 'WCHAR [260]'

What can I do to fix this?

0


a source to share


4 answers


Provide a literal wide string and use the secure copy feature:

wcscpy_s(gcap.wszCaptureFile, L"Capture.avi");

      



The literal string provides terminating null bytes.

+3


a source


You cannot assign a wszCaptureFile array with = (as you did). You can use copy methods like strcpy .

wcscpy and _mbscpy are wide-value and multibyte versions of strcpy



Example:

wcscpy (gcap.wszCaptureFile, L "Capture.avi");

+4


a source


UPDATED based on the comments on the answer ... and consider wstrcpy_s as well.

wstrcpy ( wszCaptureFile, L"Capture.avi" );

      

+2


a source


Casting your string to a WCHAR element is not as a WCHAR array as you'd hope. Try:

wszCaptureFile = L"Capture.avi\0";

      

-4


a source







All Articles