views:

310

answers:

4

Hi, I am trying to modify the amcap, an application from Windows SDK's example to capture video from UVC webcam having resolution 1600x1200px.

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

WCHAR wszCaptureFile[260]; 

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

gettnig error:

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

Please help.

-Rahul

+2  A: 

UPDATED based on comments to the answer... and consider wstrcpy_s too.

wstrcpy ( wszCaptureFile, L"Capture.avi" );
kenny
... and wstrcpy_s(...) is the safe implementation.
Daniel A. White
He also need to use L prefix:wstrcpy ( wszCaptureFile, L"Capture.avi" );
Mladen Jankovic
Daniel is correct the safe version is better, but a little more complicated given his experience with C, the simple version is better for now.
kenny
The secure version is no more complicated - there is no need to provide a size parameter when the target is an array
James Hopkin
+4  A: 

You cannot assign the array wszCaptureFile with = (as you have done). You can use the copy methods like strcpy.

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

ex:

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

aJ
A: 

Your casting your string to a WCHAR element not a WCHAR array as you are hoping. Try:

wszCaptureFile = L"Capture.avi\0";
ChrisBD
+3  A: 

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

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

The literal string provides the terminating zero bytes.

James Hopkin
It works ... thank you very much. :)
Rahul2047