Posted on 2004-04-05
Last Modified: 2013-11-25
   I need to write an MFC Dialog that communicates with a delphi program. The delphi program is the master which will call up this MFC dialog and communicate with it via windows messages. The delphi program and the MFC dialog must run in parallel.

I wrote the MFC Dialog as an MFC regular DLL. The dialog is created at the initinstance of the winApp in the MFC DLL.
However, the MFC Dialog does not seem to have its own message queue becoz it is not refreshed. What is the correct way to do this?


Question by:pcssecure
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Accepted Solution

chensu earned 125 total points
ID: 10763023
Is it a modal or modeless dialog box? Modal dialog requires a valid parent window to be modal. Check out

How to Create a Modal Dialog from Within a USRDLL;en-us;121947

Author Comment

ID: 10763289
Modeless. Modal is not applicable because if the Dialog is modal, the master delphi program will not be able to continue until the user clicks on the OK button.
LVL 16

Expert Comment

ID: 10763837
What do you mean by "it is not refreshed"? Do you send some 'refreshing' messages to the dialog and it doesn't react?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10763871
Let me rephrase the question.

I need to do some number crunching in a win32 console program and update a dialog as the number crunching progresses. Also, I want to write the modeless CDialog as a MFC regular DLL. How can I achieve this?

Do I need to create a separate thread for the message pump of the MFC DLL?
As it is now, when I add a message pump (while loop) to the winApp class, it seem to be taking up all the processing time and I am not able to return to the number crunching program to do my data processing.

How do I make the MFC DLL's message pump run on a separate thread?

Please advise.

LVL 15

Assisted Solution

lakshman_ce earned 125 total points
ID: 10765949
>Do I need to create a separate thread for the message pump of the MFC DLL?
Have your own class derived from CWinThread and have a class derived from CFrameWnd. Associate your CFramewnd derived class with your modelless dialog. And in the initinstance of CWinThread derived class call show dialog. Add required message handlers to your CWinThread derived class.
Please refer to the following links for more info

LVL 23

Expert Comment

ID: 10767503
>Do I need to create a separate thread for the message pump of the MFC DLL?

No. Why do you think it is a message pump problem? What exactly is the problem? Please respond to nonubik's question.

Author Comment

ID: 10773027
Thanks for all the help.

Lakshman: Do I still need to do all that if I am already wusing CWinApp? As far as i know, CWinApp is derived from CWinThread.

ChenSu: I think (though I am not sure) it is a message pump problem because i read from MSDN that for a modeless dialog in a MFC regular DLL, the message pump is owned by the application calling it.

The paragraph below is from MSDN TN011.
"Note that the CWinApp::Run mechanism doesn't apply to a DLL, since the application owns the main message pump. If your DLL brings up modeless dialogs or has a main frame window of its own, your application's main message pump must call a DLL-exported routine that calls CWinApp::PreTranslateMessage."

In my case, the win32 console program calling the MFC Dialog in the regular DLL does not have any message pump. What do I do?

LVL 23

Assisted Solution

chensu earned 125 total points
ID: 10776372
Now I understand what you are doing. I answered a similar question.

Check out

ConGui: Sample for Console I/O with GUI I/O

"The ConGui sample demonstrates how a standard console application can take advantage of some of the graphical capabilities of Windows NT.

Caution   This sample application illustrates a method by which a console application can utilize some (but not all) of the graphical user interface (GUI) capabilities of the Win32 API. It was not the original design intention of the Console layer of Windows NT to allow it to interact in this manner with the graphical API, and because of this, problems can occur if you try to accomplish too much. Therefore, exercise restraint in using the graphical Win32 API in your console application. If your needs go beyond the simple methods illustrated here, consider designing your application as a full GUI application."

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
modThree challenge 4 155
changeXy challenge 13 98
Windows shortcut location resolution on double click open 4 78
Excel Web Add-in Where is Visual Basic used 9 84
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question