Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

console app + Dialog DLL problems

1 view
Skip to first unread message

Valery Maltsev

unread,
Feb 19, 2003, 4:58:13 AM2/19/03
to
Hail everyone,

I've got problem with interbreeding console app and Dll with Nonmodal Dialog
in it. :)
Dll.h:
class CTestDLLApp : public CWinApp {
CTestDlg m_xDlg;
public:
CTestDLLApp();
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
}
Dll.cpp
BOOL CTestDLLApp::InitInstance() {
CWinApp::InitInstance();
m_xDlg.Create(CTestDlg::IDD, NULL);
m_xDlg.ShowWindow(SW_SHOW);
return TRUE;
}
CTestDlg is empty class with defined OnPaint() and resource IDD
Standard stuff from examples, nothing special.

Console.cpp
HINSTANCE hDllInst = LoadLibrary("TestDLL.dll");
_getch();
FreeLibrary(hDllInst);

That's it.
So, what I like is that after LoadLibrary I can see dialog window.
But what I don't like is that dialog process hangs while console wait for
getch() and can't even repaint itself.

Probably that's predicted behaviour, but I've no idea how to avoid dialog
from hanging.
So, what I'd like to see, that is console application and dll dialog work
independent from each other, but with possibility for console app to call
some exported function from the same dll.

Any help is appreciated.
Thank you in advance.


Justin Wan[MSFT]

unread,
Feb 20, 2003, 4:56:09 AM2/20/03
to
This is an interesting issue.

I think the cause might be the message queue. Because the console
application has not message queue while the interaction between you and the
dialog generated by DLL is implemented through windows message. Please note
repaint also depends on windows message. As a result, if you load the DLL
from your console application, you will find the dialog hang.

At the same time, if you load the DLL from a window application, for
example a dialog application, you will find the problem goes away.

1, Use MFC template to create a dialog application.
2, add the code into the OnOK function:
void CWinexeDlg::OnOK()
{
// TODO: Add extra validation here
hDllInst = LoadLibrary("G:\\my work\\post\\16199943 interaction_console
app+dll dialog\\test\\dll\\Debug\\dll.dll");
}

3, add the code into OnCancle function:
void CWinexeDlg::OnCancel()
{
// TODO: Add extra cleanup here
FreeLibrary(hDllInst);
CDialog::OnCancel();
}
--------------------
::From: "Valery Maltsev" <valery....@specs.net>
::Subject: console app + Dialog DLL problems
::Date: Wed, 19 Feb 2003 10:58:13 +0100
::Lines: 42
::X-Priority: 3
::X-MSMail-Priority: Normal
::X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
::X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
::Message-ID: <uDTCu0$1CHA.1728@TK2MSFTNGP12>
::Newsgroups: microsoft.public.vc.language
::NNTP-Posting-Host: 213.201.179.140
::Path: cpmsftngxa08!cppssbbsa01.microsoft.com!TK2MSFTNGP08!TK2MSFTNGP12
::Xref: cpmsftngxa08 microsoft.public.vc.language:182287
::X-Tomcat-NG: microsoft.public.vc.language
::
::Hail everyone,

::
::
::

This posting is provided "AS IS" with no warranties, and confers no rights.

Valery Maltsev

unread,
Feb 20, 2003, 6:16:44 AM2/20/03
to
Thanks for the answer, Justin. I almost gave up waiting.

Indeed, in windows app it works perfect. And I thought about absence of
message queue in console app, so I made a test. When I open simple
MessageBox after LoadLibrary in the same console app, dialog in dll works,
and after I close message box, it hangs again.

So, somehow message box affects dialog in dll.

Are there any ways to make dialog in dll independent from console app?

Best regards.

"Justin Wan[MSFT]" <just...@online.microsoft.com> wrote in message
news:YeE5CZM2CHA.3028@cpmsftngxa06...

Justin Wan[MSFT]

unread,
Feb 20, 2003, 7:47:11 AM2/20/03
to
To make dialog in DLL works fine, we must let it has a fine message queue
without any effects from the console application which has no message queue.

The simple method is to let DLL create a process which show a dialog.
Because the thread which masters the dialog in a different process so that
its message queue won't be affected from the original process (console
application + DLL). Please note, DLL runs as a part of the process which
loads it.


--------------------
::From: "Valery Maltsev" <valery....@specs.net>

::References: <uDTCu0$1CHA.1728@TK2MSFTNGP12>
<YeE5CZM2CHA.3028@cpmsftngxa06>
::Subject: Re: console app + Dialog DLL problems
::Date: Thu, 20 Feb 2003 12:16:44 +0100
::Lines: 119


::X-Priority: 3
::X-MSMail-Priority: Normal
::X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
::X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

::Message-ID: <#MT4lFN2CHA.1180@TK2MSFTNGP12>
::Newsgroups: microsoft.public.vc.language
::NNTP-Posting-Host: 213.201.179.140
::Path: cpmsftngxa06!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
::Xref: cpmsftngxa06 microsoft.public.vc.language:183672
::X-Tomcat-NG: microsoft.public.vc.language
::
::Thanks for the answer, Justin. I almost gave up waiting.

::>

0 new messages