I’m writing a custom text-to-speech program that uses SAPI 5, and one problem I’m facing is that enumerating voices with SpEnumTokens and iterating over them produces CSpDynamicString objects.
My question is, how do I convert CSpDynamicString to char * so I could printf them?
It looks like I’ve to use some kind of text-conversion macro from ATL. I found an example that does this (given dstrDesc is CSpDynamicString):
CSpDynamicString dstrDesc;
SpGetDescription(voiceToken, &dstrDesc);
USES_CONVERSION;
printf("%s\n", W2T(dstrDesc));
However this only prints the first character of the voice name!
Any ideas?
CSpDynamicStringimplements an operator to convert toWCHAR*and also manages theLPWSTRpointer internally. So,W2Tgets youLPTSTRpointer asprintfargument. If you have a Unicode build, this is results still in aWCHAR*pointer andprintf("%s"...expectsCHAR*argument – this is where you can have the problem you are describing.Try it this way: