Solved

char* to WCHAR*

Posted on 2004-10-09
3
645 Views
Last Modified: 2008-02-01
I'm attempting to use the MS speech SDK and in order to make this functional, I need to convert a null terminated char* (containing the text to say) to WCHAR* so that it may be plugged into Voice->Speak. I tried MultiByteToWideChar to no avail, perhaps due to a simple mistake on my part. Whatever the case may be, nothing other than the first four characters are ever spoken by the program. Is there a simpler method to accomplish this in non-MFC C++ or C, or should I continue to use MultiByteToWideChar? And if this is the case, how would one go about -properly- plugging the null terminated char* in?
0
Comment
Question by:State
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 12267057
You could use

char* psz = "some text";
WCHAR* pwsz = new wchar_t [strlen(psz) + 1];

wsprintfW ( pwsz, L"%S", psz);
0
 
LVL 86

Expert Comment

by:jkr
ID: 12267066
BTW, there's also 'mbstowcs()', which would work like

char* psz = "some text";
size_t sz = strlen(psz);
WCHAR* pwsz = new wchar_t [sz + 1];

mbstowcs( pwsz,  psz, sz + 1);

0
 

Author Comment

by:State
ID: 12267117
You're a lifesaver. Thanks muchly!
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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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

25 Experts available now in Live!

Get 1:1 Help Now