How can I fix this "error C2440: '=' : cannot convert from 'TCHAR *' to 'WCHAR [32]'"

This topic is 3702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am having trouble with a variable that I am passing into a function...
//I am calling the "Create" function below like so
//Initalize Test Texture from file

//---------------------------------------

// Create a font
bool cText::Create(cGraphics *Graphics, TCHAR *Name, int Size, bool Italic){
D3DXFONT_DESC lf;

if(Graphics == NULL || Name == NULL)
return false;
if(Graphics->GetDeviceCOM() == NULL)
return false;

// Set the font name and height
lf.Height = Size;
lf.Width  = 0;
lf.Weight = 400;
lf.MipLevels = 0;
lf.Italic = Italic;
lf.CharSet = DEFAULT_CHARSET;
lf.OutputPrecision = OUT_TT_PRECIS;
lf.Quality = CLIP_DEFAULT_PRECIS;
lf.PitchAndFamily = DEFAULT_PITCH;
lf.Italic = Italic;
lf.FaceName = Name;
//strcpy_s(lf.FaceName, Name);

// Create the font object
if(FAILED(D3DXCreateFontIndirect(Graphics->GetDeviceCOM(), &lf, &m_Font)))
return false;

return true;
}

This is producing error C2440: '=' : cannot convert from 'TCHAR *' to 'WCHAR [32]' Usually I can just use _T and TCHAR but the [32] seems to be getting in the way. I don't know. Any suggestion would help.... Regards Chad

Share on other sites
What line is actually generating the error?

Share on other sites
lf.FaceName = Name;

FaceName isn't a pointer, but an array that you need to copy the string into. You were close on the line below with the strcpy_s() call, but you need the TCHAR version of it (_tcscpy_s()).

Share on other sites
@joanusdmentia

Thanks...that worked.

Regards