views:

704

answers:

3

I want to handle some SAPI messages from a DLL, which is some sort of plugin. How to handle messages/events inside a VC++ dll. The SAPI event handling is shown in the example at: http://msdn.microsoft.com/en-us/library/ms720165%28VS.85%29.aspx

A: 

WndProc is used to recieve all messages/events directed at a window.

Your DLL should create a window and wait for messages to the window. If possible, you should implement this in your main process, or you can have the dll create a seperate thread that would create the window and wait for the message, while the actual function returns control to the process.

Sahasranaman MS
creating a window is not possible in a plugin, does a invisible windows works and then how to use the WndProc in the dll, any example
Priyank Bolia
An invisible window receiving events is impossible, as far as I know.
Sahasranaman MS
Definitely possible.
MSalters
+5  A: 

To process "normal" messages, you still need a Window object. It can be a special "message-only" window that only shares the messaging queue infrastructure with normal windows. To create it, first register your message handling class with RegisterClass(). Next, create an message queue by passing HWND_MESSAGE as the parent window to CreateWindow(). You will get back an HWND you can then to SAPI.

However, SAPI supports other interfaces as well. The ISpNotifySource documentation names 4: Windows messages, callbacks, events and COM (ISpNotifySink). To use callbacks, simply pass the address of one of your DLL methods to SetNotifyCallbackFunction.

MSalters
+1  A: 

If your code is running as a plugin, you might want to look at having SAPI call you back directly using ISpNotifySource::SetNotifyCallbackFunction instead of ISpNotifySource::SetNotifyWindowMessage. SAPI will then call your function directly when an event occurs.

Eric Brown
Already told by MSalters
Priyank Bolia