Solved

MFC DLL.

Posted on 2004-04-05
8
2,426 Views
Last Modified: 2013-11-25
Hi,
   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?

Thanks.


0
Comment
Question by:pcssecure
8 Comments
 
LVL 23

Accepted Solution

by:
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
http://support.microsoft.com/default.aspx?scid=kb;en-us;121947
0
 

Author Comment

by:pcssecure
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.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 10763837
Hi,
What do you mean by "it is not refreshed"? Do you send some 'refreshing' messages to the dialog and it doesn't react?
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:pcssecure
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.

Thanks.
0
 
LVL 15

Assisted Solution

by:lakshman_ce
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
http://www.codersource.net/mfc_tutorial_Part1.html
http://www.codersource.net/mfc_tutorial_Part2.html
http://www.codersource.net/mfc_user_interface_thread.html

-Lakshman
0
 
LVL 23

Expert Comment

by:chensu
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.
0
 

Author Comment

by:pcssecure
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?

Thanks.
0
 
LVL 23

Assisted Solution

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

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20909513.html

Check out

ConGui: Sample for Console I/O with GUI I/O
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/vcsmpcongui.asp

"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."
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Slow process to read Excel 15 124
SignTool Error with Windows 10 5 147
matchUp  challenge 9 108
Licensing Sharepoint 2016 for developers 11 47
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

773 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