NPAPI plugin hang ui shows after modal dialog popu

2019-08-12 08:27发布

问题:

Here is what I am trying to do: My partner's NPAPI plugin calls a function in my vc dll, My function displays a modal dialog and accepts user input. But after the dialog shows, firefox's plugin-hang-ui will popup after a few seconds and I have to manually close it or the NPAPI plugin will crashes after another few seconds.

HANDLE hThread - AfxBeginThread(DialogProc);//dialog diaplays in this thread
MsgWaitForMultipleObjects(1,&hThread,FALSE,INFINITE,QS_ALLINPUT);

Besides, my dialog will cause UI to hang if I set firefox as my dialog's parent window(am using getForgroundWindow() to get the handle of firefox).

I have already tried google and I do found some similar questions(like here), but the answers of these questions didn't solve my problem.

Any help will be highly appreciated.

回答1:

After a few days of search and test, I finally found 2 ways to solve this problem.

  1. Popup the modal dialog using win32 API DialogBox or DialogBoxParam, not MFC DoModal.

2.Using MFC DoModal but add a little trick in OnInitDialog, popup a messagebox and automatically close it right away. Then the dialog won't cuase the plugin to hang.

Both of 1)2) popup the dialog box in the main thread. I don't really understand why? It should be something related to windows message processing mechanism. Anyone who has any idea, we could discuss about it. :-)



回答2:

Your problem is that you are blocking the main thread. You may be opening the dialog on another thread, but when you do MsgWaitForMultipleObjects that blocks until your other thread finishes. Your function must return and cannot wait for the dialog.