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

MFC DLL and win32 console app

138 views
Skip to first unread message

Nagendra Singh

unread,
Jul 11, 2003, 10:22:04 PM7/11/03
to
hi all,

i have a win32 console app, which is linked to a MFC
statically linked DLL.

the console app is very simple and its just this.

int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "....." << std::endl;
while(1);

return 0;
}

the dll has a CWinAPP object (created by the APPWizard).
in the initinstance of this object i create a CMDIFrameWnd.
like this.

{
...
CMainFrame* pMainFrame = new CMainFrame;
pMainFrame->Create(NULL,_T("Waves Media ......));
m_pMainWnd = pMainFrame;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();

return TRUE;
}

CMainFrame is derived from CMDIFrameWnd.

now the pblm is window is not being displayed. i checked
to see if the window is being created correctly by Create
(...). its working fine.

any ideas as to why its not working properly.

nagendra.


MiniDisc_2k2

unread,
Jul 12, 2003, 10:53:16 AM7/12/03
to
[snip]

> the dll has a CWinAPP object (created by the APPWizard).
> in the initinstance of this object i create a CMDIFrameWnd.
> like this.
>
> {
> ...
> CMainFrame* pMainFrame = new CMainFrame;
> pMainFrame->Create(NULL,_T("Waves Media ......));
> m_pMainWnd = pMainFrame;
> pMainFrame->ShowWindow(m_nCmdShow);

Try changing this to

pMainFrame->ShowWindow(SW_SHOWNORMAL);

And tell me what you get. That may not be the problem, but it could be.

> pMainFrame->UpdateWindow();
>
> return TRUE;
> }
>
> CMainFrame is derived from CMDIFrameWnd.
>
> now the pblm is window is not being displayed. i checked
> to see if the window is being created correctly by Create
> (...). its working fine.
>
> any ideas as to why its not working properly.
>
> nagendra.
>
>

--
MiniDisc_2k2


Doug Harrison [MVP]

unread,
Jul 12, 2003, 11:03:13 PM7/12/03
to
Nagendra Singh wrote:

This doesn't seem like a legitimate way to structure a console application.
That said, it has no chance to work as written, because you go into an
infinite, do-nothing loop, instead of a message loop. See this MSDN topic
for more on "Regular DLLs Statically Linked to MFC":

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Regular_DLLs_Statically_Linked_to_MFC.3a_.Overview.asp?frame=true


--
Doug Harrison
Microsoft MVP - Visual C++

Nagendra Singh

unread,
Jul 13, 2003, 7:31:47 PM7/13/03
to
hi,

very interesting. it worked !!. can you please tell me
what was wrong with pMainFrame->ShowWindow(m_nCmdShow);.
never suspected that.

thanks.
nagendra.

>.
>

Nagendra Singh S

unread,
Jul 13, 2003, 8:17:17 PM7/13/03
to
hi Doug,

i went thru the article. by i didn't understand what this
para meant.

"A non-extension DLL that is linked to the MFC library
needs to have a CWinApp-derived class and a single object
of that application class, as does an executable MFC
application. The CWinApp object of the DLL, however, does
not have a main message pump, as does the CWinApp object
of an application."

i was actually able to fix the app by making a small
change to the code. the initinstance of the CWinApp
object in the DLL now looks like this.

CMainFrame* pMainFrame = new CMainFrame;
pMainFrame->Create(NULL,_T("Waves Media ......));
m_pMainWnd = pMainFrame;

// pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->ShowWindow(SW_SHOWNORMAL);
pMainFrame->UpdateWindow();

return TRUE;

so eariler there was
pMainFrame->ShowWindow(m_nCmdShow);
now we have
pMainFrame->ShowWindow(SW_SHOWNORMAL);

now as the pgm is working, without any message pump in the
main program, i guess that the message pump in the CWinApp
obj of the DLL is active. but the article says otherwise.

also the article says that

"If the DLL opens modeless dialog boxes or has a main
frame window of its own, the application's main message
pump must call a routine exported by the DLL, which in
turn calls the CWinApp::PreTranslateMessage member
function of the DLL's application object. This is
illustrated by the FilterDllMsg function exported by
DLLScreenCap.dll."

in the working app, there is a MDIFrameWindow. there is
nothing in the application which does anything what the
above para says. also in the sample mentioned in the same
article, the DLL does export the FilterDllMsg function,
but the app never uses it !!

any comments ??

nagendra.

>.
>

Doug Harrison [MVP]

unread,
Jul 13, 2003, 8:41:54 PM7/13/03
to
Nagendra Singh S wrote:

I don't understand why that fixed your app either. What do you find when you
set a breakpoint in InitInstance and _tmain and run it under the debugger?

>also the article says that
>
>"If the DLL opens modeless dialog boxes or has a main
>frame window of its own, the application's main message
>pump must call a routine exported by the DLL, which in
>turn calls the CWinApp::PreTranslateMessage member
>function of the DLL's application object. This is
>illustrated by the FilterDllMsg function exported by
>DLLScreenCap.dll."
>
>in the working app, there is a MDIFrameWindow. there is
>nothing in the application which does anything what the
>above para says. also in the sample mentioned in the same
>article, the DLL does export the FilterDllMsg function,
>but the app never uses it !!
>
>any comments ??

Trace the flow of control in the debugger. See what the call stack looks
when (if) those breakpoints mentioned earlier are hit, and trace into the
message loop. If you have an operational window, there has to be a message
loop. I'd be interested to know what the call stack looks like in the
context of the message loop.

0 new messages