In a 3rd party application I want to invoke an MFC dll which creates a modeless dialog.
The below is the exported function:

long CAPLEXPORT far CAPLPASCAL ShowTstDlg(long a, long b, long c)
{
TstDlg* pTest = new TstDlg;
pTest->Create(TstDlg::IDD, NULL);
pTest->ShowWindow(SW_SHOW);
return 1;
}

in the above code, the modeless dialog freezes.

So I have modified the code as follows:

long CAPLEXPORT far CAPLPASCAL ShowTstDlg(long a, long b, long c)
{
TstDlg* pTest = new TstDlg;
pTest->Create(TstDlg::IDD, NULL);
pTest->ShowWindow(SW_SHOW);


CString str("MQB RBS Menu");
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, str);

MSG msg;
while(WaitForSingleObject(hEvent, 0) != WAIT_OBJECT_0)
{
while(::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
:ispatchMessage(&msg);
}
}

// event cleanup
CloseHandle(hEvent);

return 1;
}

In this case, the modeless dialog works fine, but the 3rd part application hangs as the control is never returned to the 3rd party application, due to infinite while loop.


So I changed as follows:


long CAPLEXPORT far CAPLPASCAL ShowTstDlg(long a, long b, long c)
{
TstDlg* pTest = new TstDlg;
pTest->Create(TstDlg::IDD, NULL);
pTest->ShowWindow(SW_SHOW);


CString str("MQB RBS Menu");
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, str);

MSG msg;
while(WaitForSingleObject(hEvent, 0) != WAIT_OBJECT_0)
{
if(GetActiveWindow() != pTest->GetSafeHwnd()) break
while(::GetMessage(&msg, NULL, 0, 0))
{
if(GetActiveWindow() != pTest->GetSafeHwnd()) break
::TranslateMessage(&msg);
:ispatchMessage(&msg);
}
}

// event cleanup
CloseHandle(hEvent);

return 1;
}

In this case the menu is active at first. Later when I click on any other application, the again the dialog freezez.

Can I know how can this be solved?

Thanks in advance