将wchar **传递给方法的行为有所不同

时间:2015-08-08 21:23:24

标签: c++ winapi

在以下代码中,当我评论_tprintf(TEXT(" PROCESS NAME:%s \ n \ n"),* processName);我没有得到主要的输出 _tprintf(TEXT(" PROCESS NAME:%s"),processName);

如果不是,则输出正确的输出。我很困惑。为什么它表现得那样?有什么建议吗?

BOOL GetProcessImageNameFromPID::getProcessNameFromProcessID(DWORD processId,WCHAR**processName)
    {
        // here allprocessName is assigned
        if(pid == processId)
        {
            *processName = allprocessName;
            _tprintf( TEXT("PROCESS NAME:  %s\n\n"),*processName);
            return TRUE;
        }
        return( FALSE );
    }

    void main()
    {
    WCHAR* processName = (WCHAR*)malloc(sizeof(WCHAR));
        if(GetProcessImageNameFromPID::getProcessNameFromProcessID(580,&processName) == TRUE)
        {
            _tprintf( TEXT("***********\n"));
            _tprintf( TEXT("PROCESS NAME:  %s"),processName);
        }
    }

1 个答案:

答案 0 :(得分:0)

wchar字符串的格式说明符是%ls而不是%s