this was probably a bad idea to begin with since i've never messed with multithreading or the sapi... but i got the sapi working on its own, but when I put it in its own thread it wont speak anymore. I've tried over and over and over.... i'm not sure if this is the best attempt to post, but here it is, anyone have any ideas?
#include "sapi.h"
#include <process.h>
HANDLE thread;
long WINAPI speakthread( PCHAR text );
void cmdSpeak( PCHAR text) {
DWORD dwID;
DWORD dwRetVal = 0;
thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)speakthread,text,0,&dwID);
dwRetVal = WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
long WINAPI speakthread( PCHAR text ){
ISpVoice* m_pVoice;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&m_pVoice);
if( SUCCEEDED( hr ) )
{
wchar_t* wszStr;
int len = strlen(text);
wszStr = new wchar_t[len + 50];
mbstowcs(wszStr,text,len+1);
hr = m_pVoice->lpVtbl->Speak(m_pVoice,wszStr, 0, NULL);
m_pVoice->lpVtbl->Release(m_pVoice);
m_pVoice = NULL;
}
return 0;
}
I know this is messy... sorry. It's hard to be worried about elegance when half the crap I write doesnt work anyway =P
Tried finding answers via google, but info on multithreading seems kinda thin, or just way the hell over my head.
windows.h is included from another part of the project.