NPAPI plugin hang ui shows after modal dialog popu

2019-08-12 08:23发布

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).

just like this picture shows

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.

2条回答
仙女界的扛把子
2楼-- · 2019-08-12 09:00

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.

查看更多
地球回转人心会变
3楼-- · 2019-08-12 09:02

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. :-)

查看更多
登录 后发表回答