Passing PCWSTR to a function
-
Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!
-
Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!
Vickie, usually when I write applications I decide to either use wide characters (Unicode) strings everywhere or to use normal characters thus avoiding problems like yours. But I have had the same problem you are having numerous times. There are two ways that I have used to convert plain old char arrays to wide characters: 1. Windows provides two API calls to help things along: WideCharToMultiByte and MultiByteToWideChar these functions take quite a few parameters and can be quite cumbersome to use. 2. Use wcstombs and mbstowcs (this is the method I prefere). Look them up in your doco but this will give you an idea: char mBuf[255]; wchar_t wBuf[255]; i = mbstowcs( bBuf, mBuf, 255 ); hope this helps ;) Accept that some days you are the pigeon and some days the statue.
-
Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!
ummm is the app a unicode (or wide char) app? if so all your strings will be wide char so passing a string ptr is as easy as Speak(szString) or Speak ((LPCTSTR)csString) if the app isnt unicode then u have to use the conversion macros USES_CONVERSION; W2A(blah blah blah) A2W(blee blee blee) ;) mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them