We help IT Professionals succeed at work.
Get Started

Copy CString to TCHAR*

PMH4514 asked
Last Modified: 2010-07-14
How do I copy the value of a CString into a TCHAR* ??

Note, a UNICODE build.

For example:

TCHAR* szTest = NULL;                                  // watcher shows  0x00000000  ""
CString sTest = _T("hello world");                   // watcher shows  0x0d27dff8 {"hello world"}
szTest = sTest.GetBuffer(sTest.GetLength());   // watcher shows 0x0ce86ed4 "hello world"  looks like a copy to me!?

after sTest.Empty() the watcher for sTest shows 0x0d27dff8 {""} but now szTest in the watcher shows 0x0ce86ed4 "???????????????????????????????????????"

what am I doing wrong?


Watch Question
Senior Software Engineer
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE