'strcpy':不能将参数2从'WCHAR *'转换为'const char *

时间:2021-11-16 20:13:43

Having some issues with strcpy...

和strcpy有问题……

Getting this error:

得到这个错误:

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

strcpy':不能将参数2从'WCHAR *'转换为'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)";
}

2 个解决方案

#1


8  

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.

WCHAR项目需要wcscpy,而不是strcpy。但真正的问题是你要把宽弦转换成窄弦。因为你好像在Windows上。

#2


0  

It's pretty obvious from the error: strcpy expects const char* as the second parameter and you are passing WCHAR*

从错误中可以很明显地看出:strcpy期望const char*作为第二个参数,并且您正在传递WCHAR*

#1


8  

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.

WCHAR项目需要wcscpy,而不是strcpy。但真正的问题是你要把宽弦转换成窄弦。因为你好像在Windows上。

#2


0  

It's pretty obvious from the error: strcpy expects const char* as the second parameter and you are passing WCHAR*

从错误中可以很明显地看出:strcpy期望const char*作为第二个参数,并且您正在传递WCHAR*