WPF application which calls an API, which needs a

2019-07-30 11:58发布

问题:

I have a WPF application that calls an API to operate a device (a scanner). This API is COM based, and internally has a hidden window that the scanner sends messsages too. The intent of the API is to turn those windows messages into COM events. The problem is that the WPF application doesn't have a message pump, and therefore none of the messages are being delivered to the hidden window. Therefore none of the events are fired and it looks like the scanner is not responding.

How should I create a message loop in the WPF application that will be able to dispatch messages to the invisible window?

回答1:

This method can start a message pump if you don't have one already: http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.run.aspx

Note that each thread owns a separate message pump, which pumps messages for all windows created by that thread. You need to find the thread that created the hidden window.