Thread: char to WCHAR

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    char to WCHAR

    Hey, is there any function to convert a char to a WCHAR? I can't get the speach function to work because it wants a WCHAR. I've tried type casting but it doesn't work. I can hard code the file in but i want the user to be able to choose which file they want. To hard code it I have to add an L infront of the quation marks for the text, but how could i do something like this with a normal char?

    The code below doesn't compile and gives me the following error:
    cannot convert parameter 1 from 'char [255]' to 'const unsigned short *
    Code:
    #include <sapi.h>
    #include <iostream.h>
    #include <fstream.h>
    
    int main(int argc, char* argv[])
    {
    	ifstream file;
    	char string[255];
        ISpVoice * pVoice = NULL;
    
        if (FAILED(::CoInitialize(NULL)))
            return 0;
    
    	cout << "Enter the name of a text file you want spoken: ";
    	cin  >> string;
    
        HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
        if( SUCCEEDED( hr ) )
        {
            hr = pVoice->Speak(string, SPF_IS_FILENAME | SPF_IS_XML, NULL);
            pVoice->Release();
            pVoice = NULL;
        }
    
        ::CoUninitialize();
        return 0;
    }
    Last edited by pinkcheese; 07-26-2002 at 09:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM