?
Solved

char* to WCHAR*

Posted on 2004-10-09
3
Medium Priority
?
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1200 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

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

770 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