How can I prevent a third party library from displaying a MessageBox?

后端 未结 3 1984
时光取名叫无心
时光取名叫无心 2020-12-30 03:58

I am integrating a third party C-based SDK into my .NET application. The application will run as a Windows service on a server, so it should not interact with the user in a

3条回答
  •  遥遥无期
    2020-12-30 04:47

    This is not very easy. I would think the only way is to write a message hook to trap messages pumped through all the windows message loops on the system. But I'm not even sure that a service can create a message hook given it does not have access to the default window station under its default credentials (LocalSystem). So task # one would be to see if that would actually work.

    But here is a rough sketch of how I would try to do it outside of a service context and you can see if it applies:

    1. Create a windows hook to trap messages from all windows message queues on the system.
    2. Trap all WM_CREATE messages, and probe the CREATESTRUCT paramter for messages that may be originating from your third-party library. You may have to log all the WM_CREATE messages and then analyze the data to see how you can differentiate your library's dialog from any other dialog on the system. (Many times the "lpszName" member differs between dialog implementations.)
    3. if you believe the particular WM_CREATE came from your library, return a "handled" response from your message hook and don't call the next message handler in the chain.

    This is all very dicey mind you, but it is the path that seems like it has any chance to me.

提交回复
热议问题