Author Topic: Speech and HID Together COINITIALIZE NOT CALLED  (Read 2181 times)

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Speech and HID Together COINITIALIZE NOT CALLED
« on: December 10, 2009, 04:42:58 pm »
Hello

You wrote:
Quote
I’m writing a tool for a blind friend to operate an HID joystick, and I was hoping to be able to say “UP”/”DOWN”, etc.
I’ve written a Delphi 7 program that decodes joystick movements, and another that speaks the words.
Both work fine independently.
When I try any speak operation after the HID is activated, I get a “COINITIALIZE NOT CALLED” fatal error.
I don’t see any coinitialize methods or properties on either control, it’s not in the help or the forum, and I don’t see any demo that includes both at the same time.
How do I coinitialize both controls at the same time?

I see in your code:

Code: [Select]

procedure TForm1.nrHid1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
var EW, NS : string;
begin
   ....
   Speak('Hello!');
end;

procedure TForm1.Speak (PText : string);
begin
  nrSpeech1.nrCommTAPI := nil;
  nrSpeech1.Text.Text:= PText;
  nrSpeech1.VoiceIndex := 0;
  nrSpeech1.Speak;
end;



You created nrSpeech1 instance in main windows app thread.

Then you call nrSpeech1.Speak(); method from another thread that
was created by nrHid class for I/O monitoring. And the additional call
of function Coinitialize is needed.

Code: [Select]
       
  CoInitialize (nil);
  nrSpeech1.Speak;
  CoUnInitialize;

But better if you will call TForm1.Speak (PText : string); method from main windows
thread. I hope you will understand following sample:

Code: [Select]

TForm1 = class()
...
    procedure WM_My_Speech(var Msg:TMessage); message WM_USER + 10;
end;

// process message ...

procedure TForm1.WM_My_Speech(var Msg: TMessage);
begin
  Speak (String(PChar(Msg.WParam)));
end;


procedure TForm1.nrHid1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
begin
   .....
   // !!!!!!!!!!!! Speak ('Hello'); !!!!!!!!!!!!!!!!!!!!
   PostMessage(Handle, WM_USER + 10, Dword(PChar('Hello')), 0); // send message to main form thread
end;

Roman Novogorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Speech and HID Together COINITIALIZE NOT CALLED
« Reply #1 on: December 10, 2009, 05:56:33 pm »
Hello

This problem was resolved in v9.00 and higher.
Now you can call Speak() and any other COM methods from nrComm Lib event handlers.

Roman Novgorodov
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.