OutputDebugString cannot convert `TCHAR*' to `char*'

I got this from EE and try to use it but got errors.

void DbgPrintf(LPTSTR fmt,...    )
{
    va_list marker;
    TCHAR szBuf[256];

    va_start(marker, fmt);
    wvsprintf(szBuf, fmt, marker);
    va_end(marker);

    OutputDebugString(szBuf);
    OutputDebugString(TEXT("\r\n"));
}

I used it like this:
int number = 1;
DbgPrintf("DEBUG: Number is %d", number);

But I got the following error message:

error: cannot convert `const char*' to `TCHAR*' for argument `1' to `void DbgPrintf(TCHAR*, ...)'

Thanks for the help.

Ming
LVL 1
mybluegrassAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
Try: DbgPrintf(_T("DEBUG: Number is %d"), number);
0
evilrixSenior Software Engineer (Avast)Commented:
Or: DbgPrintf(TEXT("DEBUG: Number is %d"), number);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pgnatyukCommented:
or simply add 'L' before the const char* in the place you call this DbgPrintf function. Like
DbgPrintf(L"x = %d", x);
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

evilrixSenior Software Engineer (Avast)Commented:
>> or simply add 'L' before the const char*

You can do that but it will then fail to build in non Unicode builds. the _T or TEXT macro ensures L is used where necessary and not used where it's not necessary.
0
ambienceCommented:
You need to change the function a bit
void DbgPrintf(LPCTSTR fmt,...    )
i.e. LPTSTR -> LPCTSTR
 
If that does not solve the issue, then also apply the suggestions mentioned earlier.
0
evilrixSenior Software Engineer (Avast)Commented:
>> i.e. LPTSTR -> LPCTSTR
Although I agree passing as a const is better this is not the cause of the error. This is clear by looking at the error message.

cannot convert `TCHAR*' to `char*'
0
pgnatyukCommented:
and then here will be an error:
OutputDebugString(szBuf);

This is OutputDebugStringW in this project (it does support Unicode character set).
0
pgnatyukCommented:
Sorry, the error will here first
  wvsprintf(szBuf, fmt, marker);
0
pgnatyukCommented:
BTW, "Unicode character set" is the default now. For pure Windows app it is a nonsense to support Multibyte.
 
0
ambienceCommented:
@evilrix:
error: cannot convert `const char*' to `TCHAR*' for argument `1' to `void DbgPrintf(TCHAR*, ...)'
0
evilrixSenior Software Engineer (Avast)Commented:
Heh. Ok, it seems the error was presented twice with conflicting information. I missed that. Thanks for pointing it out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.