简体   繁体   中英

How to use WndProc from a C++ dll?

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

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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM