Solved

Converting data between wchar_t & LPTSTR

Posted on 2000-04-27
3
802 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

680 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