Solved

Converting data between wchar_t & LPTSTR

Posted on 2000-04-27
3
794 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
ID: 2754522
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
ID: 2754570
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
ID: 2754981
#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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

14 Experts available now in Live!

Get 1:1 Help Now