开发者

TRACE Macro Error When Attempting to Pass String Variable

开发者 https://www.devze.com 2023-03-07 01:00 出处:网络
My calls to the TRACE macro are resulting in an error when I attempt to pass a string to it like so: TRACE(_T(\"PrintAppMsgTrace: %s\"), _T(GetCmdIdStr( pMsg[APP_MSG_CODE_OFFSET] )));

My calls to the TRACE macro are resulting in an error when I attempt to pass a string to it like so:

TRACE(_T("PrintAppMsgTrace: %s"), _T(GetCmdIdStr( pMsg[APP_MSG_CODE_OFFSET] )));

This is the error I get in the console window output:

_CrtDbgReport: String too long or IO Error

Here is the prototype for GetCmdIdStr:

char * GetCmdIdStr( BYTE id );

GetCmdIdStr returns a poin开发者_如何学Cter to memory containing something like "APP_ZDO_NLME_LEAVE_REQ". It essentially works like this:

char * GetCmdIdStr( BYTE id )
{
    return "APP_ZDO_NLME_LEAVE_REQ";
}

Why am I getting this error? Any thoughts would be appreciated. Thanks.


The _T() macro is used on string literals. It expands to either just the original string literal, if you're compiling ANSI, or the string literal with an L prefix if you're compiling UNICODE. You can't apply it to the return value of a function.

If possible, the simplest thing to do would be to change the GetCmdIdStr function to return TCHAR instead of char:

TCHAR * GetCmdIdStr( BYTE id )
{
    return _T("APP_ZDO_NLME_LEAVE_REQ");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消