views:

45

answers:

1

I'm using WinForms, and I'm trying to get SetNotifyWindowMessage() to send a message to the WndProc, but it does not do so.

The function call:

HRESULT initSAPI(HWND hWnd)
{
  ...
  if(FAILED( g_cpRecoCtxt->SetNotifyWindowMessage( hWnd, WM_RECOEVENT, 0, 0 )))
    MessageBoxW(hWnd, L"Error sending window message", L"SAPI Initialization Error", 0);
  ...
}

The WndProc:

LRESULT WndProc (HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
   case WM_RECOEVENT:
      ProcessRecoEvent(hWnd);
      break;
   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
}

Note: initSAPI() is called on a mouse click event.

A: 

Have you called ISpRecoContext::SetInterest as well? SetNotifyWindowMessage specifies what to do when an event occurs, but doesn't specify what events to listen for.

Eric Brown
Yes I have, I've set the interest to `SPEI_RECOGNITION`. The problem is, when the event occurs, it didn't do what it was told to do.
manuel
Are you using an inproc or shared recognizer? You have to do much more initialization for an inproc recognizer (setting the engine, in particular), and if you don't set the engine up, SAPI won't give you an error code, but it also won't do any recognitions.
Eric Brown
I'm using a shared recognizer. I've done the engine, context, grammar, and rules setting. What do you think?
manuel
Try adding more event flags. In particular, SPEI_SR_AUDIO_LEVEL is useful to make sure that the recognizer is actually processing audio.
Eric Brown