Solved

Converting data between wchar_t & LPTSTR

Posted on 2000-04-27
3
786 Views
Last Modified: 2013-11-20
how can I convert :
LPTSTR lpt = "tthtri"

to/from

wchar_t wc = L"tthtri"

already use mbstowcs() but the value is different
0
Comment
Question by:ahTri
  • 2
3 Comments
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
LPTSTR is defined as LPWSTR (or wchar_t*) when UNICODE is defined.

LPTSTR is defined as LPSTR (or char*) when UNICODE is NOT defined.

>>already use mbstowcs() but the value is different

What do you mean?

mbstowcs()/wcstombs() work fine.

0
 

Author Comment

by:ahTri
Comment Utility
yeah sorry

wchar_t * wc;
LPTSTR lpt = "tthtri";

if I use mbstowcs() to convert lpt to wc, when I convert back to string it become "t22222"

can you give me the code that convert it please

0
 
LVL 15

Accepted Solution

by:
NickRepin earned 50 total points
Comment Utility
#include <windows.h>
#include <iostream.h>
#include <tchar.h>
#include <string.h>

void main(void)
{

   wchar_t wc[16];
   TCHAR res[16];
   LPTSTR lpt = "tthtri";
   mbstowcs(wc,lpt,16);
   wcstombs(res,wc,16);  
   cout<<res<<endl;
}


0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now