Click here to Skip to main content
14,970,653 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Guys,

I am facing a weird problem to put the database query in CString Format with
Unicode defined.

I am giving a simple example of my problem.
CString str1;
int value = 123;        
str1.Format(_T("select * from Table Where Max > %d"), value);
Getting output only 1st character of entire string.
Output-> "s"  
instead of -> "select * from Table Where Max > 123"

I also tried this one but It's not getting integer variable and displaying like this:
str1.Format((LPCTSTR)("select * from Table Where Max > %d"), value);
OutPut-> "select * from Table Where Max > %d"

Please give me some solution because I tried everything but I didn't get where I did
Updated 10-Jul-12 4:05am
nv3 10-Jul-12 10:45am
I'd check two things:

Is str1 defined as CString or CStringA or CStringY?

Is UNICODE and _UNICODE defined?

The latter problem would be my guess, so the Windows headers think they compile for Unicode and MFC headers think they compile of MBCX and hence select the wrong library.
saqib.akhter 10-Jul-12 11:04am
Thanks for reply..
but I got a solution that unicode display string setting was not enable that's why it happened.

Thanks for your investigation that could also help me in future...

1 solution

I got solved myself actually I just did silly mistake.
There is a one unicode setting has to be enable in Visual Studio.

Here is the solution:

Check the following setting in Visual Studio:
Check Display unicode strings checkbox.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900