'strcpy' : cannot convert parameter 2 from 'WCHAR *' to 'const char *

E3pO picture E3pO · Dec 28, 2011 · Viewed 7.3k times · Source

Having some issues with strcpy...

Getting this error:

strcpy' : cannot convert parameter 2 from 'WCHAR *' to 'const char *

Here is the code...

char FunctionName[ 256 ]; 
UFunction *pUFunc                        = NULL;
strcpy( FunctionName, pUFunc->GetFullName() );

And also:

WCHAR* UObject::GetFullName ()
{
    if ( this->Class && this->Outer )
    {
        static WCHAR ObjectName[ 256 ];

        if (Outer == NULL)
        {
            wsprintf(ObjectName, L"");
        }
        else
        {
            if (Outer->Outer)
                wsprintf(ObjectName, L"%s %s.%s.%s", Class->Name.GetName(), Outer->Outer->Name.GetName(), Outer->Name.GetName(), Name.GetName());
            else if(Outer)
                wsprintf(ObjectName, L"%s %s.%s", Class->Name.GetName(), Outer->Name.GetName(), Name.GetName());
        }
        return ObjectName;
    }

    return L"(null)";
}

Answer

bmargulies picture bmargulies · Dec 28, 2011

You need wcscpy for WCHAR items, not strcpy. But the real problem is that you are trying to convert a wide string to a narrow string. WideCharToMultiByte since you seem to be on Windows.