CoInitialize fails in dll
Posted
by Quandary
on Stack Overflow
See other posts from Stack Overflow
or by Quandary
Published on 2010-04-18T13:27:45Z
Indexed on
2010/04/18
13:33 UTC
Read the original article
Hit count: 292
Question: I have the following program, which uses COM to use the Microsoft Speech API (SAPI) to take a text and output it as sound.
Now it works fine as long as I have it in a .exe. When I load it as .dll, it fails. Why?
I used dependencywalker, and saw the exe doesn't have MSVCR100D and ole32, so I loaded them like this: LoadLibraryA("MSVCR100D.DLL"); LoadLibraryA("ole32.dll"); but it didn't help...
Any idea why ?
#include <windows.h>
#include <sapi.h>
#include <cstdlib>
int main(int argc, char* argv[])
{
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **) &pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(L"Noobie was fragged by GSG9 Googlebot", 0, NULL);
hr = pVoice->Speak(L"Test Test", 0, NULL);
hr = pVoice->Speak(L"This sounds normal <pitch middle = '-10'/> but the pitch drops half way through", SPF_IS_XML, NULL );
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
return EXIT_SUCCESS;
}
© Stack Overflow or respective owner