0

I have a C# program which loads a C++ unmanaged dll and calls its functions. The dll performs some operations and if an error or exception occurs, it displays a windows message box. So if no error is encountered, no message box will be shown. It is worth mentioning that I don't have the source of the dll.

Now if I call a function of the dll in C#, the only way for me to assure that it is successfully executed is to check whether any message boxes is shown during its call. My question is, how can I do this? i.e. detect messagebox calls by the dll?

polfosol ఠ_ఠ
  • 1,840
  • 26
  • 41
  • 1
    Since your application is calling the functions, try capturing `WM_INITDIALOG` in `WndProc` – Hatted Rooster Jul 03 '16 at 07:57
  • Could you give more details? I am not so experienced in c# @GillBates – polfosol ఠ_ఠ Jul 03 '16 at 07:58
  • Displaying a message box in response to an exception does not really seem like reasonable behavior for a DLL. The DLL should throw the exception, and let the *client* code handle it. Only if the client does not handle it should a default unhandled exception handler display a message box. Are you sure these aren't simply debugging messages telling you that you're using the DLL incorrectly (e.g., passing an incorrect parameter)? – Cody Gray - on strike Jul 03 '16 at 09:47
  • How would that work, @Gill? WM_INITDIALOG is not sent at all for a standard message box (i.e., call to MessageBox API). And if the DLL is creating its own window to display a dialog box, it is surely specifying its own window procedure. The messages would go to its wnd proc, not to yours. – Cody Gray - on strike Jul 03 '16 at 09:49
  • @CodyGray It is a poorly written C++ code that the designer decided to manage the exceptions internally, and just show some messages. Sadly I am stuck with it for the moment and don't have time or resources to change anything (In response to your question, yes I am sure). – polfosol ఠ_ఠ Jul 03 '16 at 09:54
  • And thanks for the duplicate link @CodyGray – polfosol ఠ_ఠ Jul 03 '16 at 09:56

1 Answers1

0

You can achieve it by hooking MessageBox series WINAPI if the DLL uses standard message box procedure.( Google WINAPI hook c#)

But if the DLL don't use standard messageboxes, you may need to hook CreateWindow or etc.

Keyu Gan
  • 711
  • 5
  • 17