CWinApp and message loop thread

I'm wondering why WIN32 dlls (no theApp CWinApp appears to be the only 
difference) work, but converting the project to MFC make the windows not be 
repainted.

I assume i'm missing something going on about the threading. The code starts 
a thread in these WIN32 dlls that constructs some windows and becomes a 
message loop. CWinApp appears to interfere with this. But my own message loop 
does get a bunch of WM_PAINT and WM_MOUSEFIRST messages. The difference 
appears to be that other messages go to the CWinApp message loop, but i'm not 
sure even about that yet.
0
ultranet (61)
3/24/2006 12:06:01 AM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
866 Views

Similar Articles

[PageSpeed] 39

Are you saying you have your message loop in addition to MFC's message
loop? How m any UI threads do you have? Why do you have your message
loop if you have only one UI thread?

------
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6842)
3/24/2006 12:44:37 AM
It was something else, and it's working in an MFC dll now. 
Question: does CWinApp spawn a new thread to call its Run method as a 
message loop? If so, i guess it's a tad more efficient to have 1 MFC dll for 
multiple apps, than a separate MFC dll for each.

Thanks.

"ultranet" wrote:

> I'm wondering why WIN32 dlls (no theApp CWinApp appears to be the only 
> difference) work, but converting the project to MFC make the windows not be 
> repainted.
> 
> I assume i'm missing something going on about the threading. The code starts 
> a thread in these WIN32 dlls that constructs some windows and becomes a 
> message loop. CWinApp appears to interfere with this. But my own message loop 
> does get a bunch of WM_PAINT and WM_MOUSEFIRST messages. The difference 
> appears to be that other messages go to the CWinApp message loop, but i'm not 
> sure even about that yet.
0
ultranet (61)
3/24/2006 3:52:03 PM
> Question: does CWinApp spawn a new thread to call its Run method as a
> message loop? If so, i guess it's a tad more efficient to have 1 MFC dll
for
> multiple apps, than a separate MFC dll for each.

There is only one thread. Why do you think there are multiple threads. All
windows in an application, regardless of how many dlls they are created
from, all belong to single UI thread by default.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com



0
ajaykalra (6842)
3/24/2006 4:31:41 PM
Well, WinMain calls InitInstance, and then Run. Run is a blocking call, that 
never returns until app is being destroyed. Doesn't this mean that Run gets 
executed on a separate thread? Otherwise, WinMain would never return until 
the app is done.
Am i mising something.

P.S. In our case, the dll is loaded from a Java thread, which probably isn't 
the main thread.

"Ajay Kalra" wrote:

> > Question: does CWinApp spawn a new thread to call its Run method as a
> > message loop? If so, i guess it's a tad more efficient to have 1 MFC dll
> for
> > multiple apps, than a separate MFC dll for each.
> 
> There is only one thread. Why do you think there are multiple threads. All
> windows in an application, regardless of how many dlls they are created
> from, all belong to single UI thread by default.
> 
> --
> Ajay Kalra [MVP - VC++]
> ajaykalra@yahoo.com
> 
> 
> 
> 
0
ultranet (61)
3/24/2006 5:22:01 PM
ultranet wrote:

> Well, WinMain calls InitInstance, and then Run. Run is a blocking call, that 
> never returns until app is being destroyed. Doesn't this mean that Run gets 
> executed on a separate thread? Otherwise, WinMain would never return until 
> the app is done.
> Am i mising something.
> 

Yes. WinMain doesn't return until the app is done.

David Wilkinson
0
no-reply8010 (1791)
3/24/2006 6:20:33 PM
I see. But if the dll is loaded from a Java thread, and WinMain doesn't 
return, does that mean LoadLibrary spawns a new thread for each dll that has 
a WinMain (WIN32 and MFC projects have one i believe)?

"David Wilkinson" wrote:

> ultranet wrote:
> 
> > Well, WinMain calls InitInstance, and then Run. Run is a blocking call, that 
> > never returns until app is being destroyed. Doesn't this mean that Run gets 
> > executed on a separate thread? Otherwise, WinMain would never return until 
> > the app is done.
> > Am i mising something.
> > 
> 
> Yes. WinMain doesn't return until the app is done.
> 
> David Wilkinson
> 
0
ultranet (61)
3/24/2006 7:01:02 PM
> does that mean LoadLibrary spawns a new thread for each dll

No it does not. Loading of a Dll has no relationship with creation of a
thread. You can have 100s of DLLs, all in one thread. A DLL, when
loaded, can choose to launch a thread.

-----
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6842)
3/24/2006 7:25:51 PM

"ultranet" wrote:

> I see. But if the dll is loaded from a Java thread, and WinMain doesn't 
> return, does that mean LoadLibrary spawns a new thread for each dll that has 
> a WinMain (WIN32 and MFC projects have one i believe)?

I know that Java's System.loadLibrary returns right away, so based on above, 
looks like there is a thread spawned.
0
ultranet (61)
3/26/2006 10:49:31 PM
> I know that Java's System.loadLibrary returns right away, so based on
above,
> looks like there is a thread spawned.

No, there is no new spawned thread.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com



0
ajaykalra (6842)
3/28/2006 1:05:28 AM

"Ajay Kalra" wrote:
> No, there is no new spawned thread.
> 
I think i confused WinMain and _DllMain. WinMain is used if it's an app, but 
if it's a dll, DllMain is used. I concur that DllMain returns immediately, 
but what i don't understand is whether MFC dlls, w/ their CWinApp, which is 
supposed to be a thread, end up starting a thread when theApp object is 
instantiated. 
Here's one quote from "Multithreading: Creating User-Interface Threads":
'... The main application thread (provided in your CWinApp-derived class) is 
already created and started for you.  ...'

Why i wonder about it: we have Win32-based code, that starts our own 
Win32-based message loop (using _beginthread), w/o MFC message mapping. It 
appears it might be easier to just keep that code going, instead of changing 
the switch cases to a message map. In that case, i'd probably prefer to 
terminate theApp UI thread by overriding Run method, or something of that 
sort.
The alternative would be to convert _beginthread and our message loop into 
MFC message maps, but it might be messy, because all this is done from Java 
threads, and would require sending a message to CWinApp message loop, and 
getting the window handles back using another message, etc.
0
ultranet (61)
3/28/2006 9:41:02 PM
I think you are confusing number of threads in a MFC app with CWinApp
objects. To simplify, you could have 10 MFC Regular DLLs, each with its
own CWinApp. All these DLLs can be loaded by a MFC application and
there would be only *one* UI thread. 

---
Ajay

0
ajaykalra (6842)
3/29/2006 1:44:06 AM
Reply:

Similar Artilces:

Problem with DllMain without a CWinApp
Hello I have a TSP (Telephony Service Provider) DLL. This DLL has two parts: a GUI-part which uses some MFC stuff and a non-GUI part (doesn't use MFC). Everything works fine. I don't have a CWinApp object and I don't want / need one. Now I need to add some multithreading support and therefore need to initialize a critical section Win32 object only once (when loading / unloading the DLL). This can only be done in DllMain as far as I found out. When I define such a function, I get a duplicate symbol (DllMain) linker error conflicting with uafxcwd.lib(dllmodul.obj). Current ...

Message box with multiple buttons
Im trying to create a message box that has the message "Do you want t print?" with buttons "Yes" and "No". When yes is selected the prin macro is activated. When no is selceted the macro stops and goes bac to the work sheet. Can anyone help me? Thank -- Message posted from http://www.ExcelForum.com Code ------------------- If MsgBox("DO YOU WANT TO PRINT?", vbYesNo, "PRINT") = vbYes Then 'Your code for print macro Else End End If ------------------- Rolli -- Message posted from http://www.ExcelForu...

Read or sel message in outlook re-appears as new message on Blackb
Using Outlook 2007 on pc and Imap exchange server on blackberry A read or even just a selected message in inbox from outlook re-appears as new message on Blackberry. Searched the internet but no solution found yet.......... Verry anoying! Anyone a clue? Best regards George Why IMAP? -- Ed Crowley MVP "There are seldom good technological solutions to behavioral problems." .. "George AV" <George AV@discussions.microsoft.com> wrote in message news:F31E21F4-FC14-4D58-AF5D-ED5C3BE4F547@microsoft.com... > Using Outlook 2007 on pc ...

CWinApp
When I exit an app via the "Exit" menu event that maps to "OnFileExit" I get control before anything has been done to alter the state of the app. I can check to be sure that the user has not left the database he is working on in an unacceptable state. And cancel the exit if he needs to do more work to clean it up. When you "Close" the app via the "X" icon in the upper right hand corner of the app window I can not find an event that gives me control before anything is done to the app so I can cancel the close if I need to. Any idea how to get th...

Messages Cut off
A recipient receives forwarded mail messages that are cut off in random locations throughout the email. Outlook 2000 with latest SP. Any ideas? ...

news messages disappear
Hi All, I am using windows xp home sr3. I use outlook express to read my newsgroups. For some reason the messages disappear when I leave the current folder. This is happening on my laptop. I have my desktop and laptop configured the same way. this doesn't happen on my desktop. Can I do something to fix this? P.S. The laptop uses the same version of windows. thanks for any help. -- Regards, Gary Metzler send to: gmtravel@bellsouth.net http://www.outtasighttravel.com Msn messenger: gmetzler1150@hotmail.com Skype name: garymetz While in a newsgroup: V...

export messages in Outlook Express 6
I've tried to export messages from Outlook Express 6 and got an error message: MAPI error. Anyone knows how to get around this problem? I ran "fixmapi.exe" to create a new MAPI.DLL but still wouldn't work. Thanks fdp2001ca@hotmail.com "fdp" <fdp2001ca@hotmail.com> wrote in message news:bd7001c479bf$ca7e0f30$a401280a@phx.gbl... > I've tried to export messages from Outlook Express 6 and > got an error message: MAPI error. > Anyone knows how to get around this problem? I > ran "fixmapi.exe" to create a new MAPI.DLL but still > ...

I cant send messages
Hi I have windows live mail and have recently reformatted the hard drive for an unrelated problem. I connected back onto the net and an receiving emails ok but i cant send any. Here is the error message: The host 'mail.bigpond.com ' could not be found. Please verify that you have entered the server name correctly. Subject 'deal or no deal' Server: 'mail.bigpond.com ' Windows Live Mail Error ID: 0x800CCC0D Protocol: SMTP Port: 25 Secure(SSL): No Socket Error: 11004 I have triple checked the writing in the accounts and cannot see that i have wri...

Writing email replies UNDER the original message
I believe a reply/response should default to AFTER a question/original message. Logical? I cannot see how to do this in Vista using Office 2007. it's not an option in outlook, but you can move the insertion point to the end of the message. FWIW, I find it easier to read messages when the reply is on top - no need for me to search for the newest reply, its right on top where I can see it. It also works better on phones - especially since only the first few bytes are sent to the phone until I request the full message. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http...

Intelligent Message Filtering Question
We just installed the filter yesterday and have set the gateway SCL setting to 4. Unfortunately mail sent by the public from our comercial web site back to the home office is being given a SCL of 4 and it is archived, thus never reaching some important departments. I have added the recipient to the Exception List under Connection Filterng in Message Delivery Properties and this has not made a difference. Is there another way besides increasing the SCL to let mail from this particular domain pass through the Gateway? Thanks, Pete I would add it to the Accept section of the "Global ...

Can we intercept messages in general?
Hi, When one class sends a message to another (e.g. via SendMessage), can we intercept this message? How? I want to find out all the messages that one child window sends another, for instance. -- Thanks in advance, Juan Dent, M.Sc. It is possible to determine which messages are sent to a window. There is no way to detect only those messages that were sent from some other window. How to detect messages sent to a window depends on if the window is part of your application or another one. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com "Juan Dent" <...

Mem leak when implement Singleton pattern on CWinApp derived class
Coded my MFC app to have singleton pattern, my code looks like this: class CMyApp : public CWinApp { private: // static obj static CMyApp* MyAppInstance; // some other obj composed in this class COtherObj* obj; // private cons, I init the COtherObj here CMyApp() { obj = new COtherObj(); } public: // only way to access cons static CMyApp* GetInstance() { //check if already instantiated if( MyAppInstance == NULL) { MyAppInstance = new CMyApp(); } return MyAppInstance; } virtual int ExitInstance() { // I use ExitInstance to delete all ...

Message Size Exceeds....
I'm running Exchange 5.5 with about 160 users. I added an address to our 'Externals' container (custom recipients frequently used by a number of employees) which is very similar to a set of addresses already listed - same domain, actually. However, when anyone sends an email, a System Administrator note comes back: " Either the message size exceeds the maximum allowed for the recipient or transport, or you have exceeded the storage limit on your mailbox." This is not the case as size is not an issue with our mailboxes. Another thing is if someone sends to the address...

Detail reports on message store
I need a way (canned software, or I can write it) to be able to analyze my message store. I want to be able to report by folder, age the messages in buckets (current, 30-60 days, etc), # and size of attachements, etc. Most mail systems let you do this easily. Running Exchange 203 Enterprise. ...

Loop Macros
I am trying to write a macro that will do the following as long as there is data in column A. Range("F4").Select ActiveCell.FormulaR1C1 _ = "=IF(LEN(R4C1)<LEN(R4C5), CONCATENATE(R4C1,R4C5),CONCATENATE(R1C5,R1C1))" With Selection.Interior .ColorIndex = 38 .Pattern = xlSolid .PatternColorIndex = xlAutomatic Selection.Locked = True End With How do I write a Loop that will keep doing this on each successive row until the cell in column A is blank? Try Dim R As Range Set R = Range("F4") Do Until...

Error Message when send/receiving: An object could not be found.
Can anyone tell me why this error message comes up when I try to send/receive in Outlook? I have tried to repair using the disc, but it doesn't help this problem. ! The operation failed. An object could not be found. Thanks, Kimberley ...

Slow messag retrival
Hi, I'm running exchange 2003 sp1 on a windows 2000 sp4 server. My problem is (if it is a problem) that the massage retrival is very slow. Say I whant to make my mailbox available offline and my mailbox is 300MB it takes upp to 20min to syncronize! my machine is connected to a GB network with the exchange server!!!! is there any parameters in exchange that I can change to speed up things? the ordinary transfer is very good, 300MB takes about 7-10 sec (from my computer to and from the exchange server) Thanx for any help Regards Ted Try Outlook 2003 and cached mode. -- Ed Crowley...

Receiving the same messages over and over
Every time I open Outlook 2002, I receive the same old messages over and over. Please help, I'm at 30 messages and counting. Go to your ISP webmail and delete the messages. Then, turn off your incoming/outgoing AV from scanning your mail. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, Chris asked: | Every time I open Outlook 2002, I receive the same old | me...

Exchange 2003 Message Tracking #4
Hi, We have just moved to running Exchange 2003 with Outlook 2003, we have had someone emailing from externally to a couple of our users at 09:44 yesterday and the users are saying they don't recieve the mail. So I checked the Message Tracking Centre, and it isn't listed for the time it was supposed to be sent. There was an earlier message (09:15) sent from the same person to the same reciepients, with the same subject, so I checked the Message History. In the message history, there are events at 09:15 showing the message being submitted and delivered to the local user, after this ...

Message to all outgoing
Is it possible add a message to all outgoing mails for all users at one time, we are using Exchange 2003 ? Jack -------------------------------------------------------------------------------- Jeg beskyttes af den gratis SPAMfighter til privatbrugere. Den har indtil videre sparet mig for at f� 16769 spam-mails Betalende brugere f�r ikke denne besked i deres e-mails. Hent en gratis SPAMfighter her. You mean like a disclaimer? Nothing native or built-in. - Using a transport event sink - (the following code has a is a painful exercise at best, doesn't work for locally delivered messa...

view pics in body of message ???
Is there any EASY way to enable viewing attched pictures in the message body of the email I receive (Outlook 2003) ? When I receive a pic attachment...it is only viewable by opening each pic separately, as opposed to just scrolling down through the message and seeing them in the body of the email ( how it was in OE). When I looked up the help on "view attachment in body of message" I got this technobabble : 1.. Use the keyboard to choose the Customize Current View command (View menu, Arrange By, Current View submenu). 2.. Click Fields, and then click New Field. 3.. In t...

"Could not find a part of the path" error message
Hi, I am trying to load XML files from a mapped drive into my web application and I get the above error. When I load the files from my local drives, it works fine. Can anyone help? Thanks. ********************************************************************** Sent via Fuzzy Software @ http://www.fuzzysoftware.com/ Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources... ...

CWinApp in a dll?
Is it possible to create a CWinApp object in a DLL? I don't want to give access to the CWinApp object outside of the DLL so that is not an issue. In fact I don't want to give access to any of the MFC objects contained within the DLL. Murrgon Yes, you can do this. As far as exposing the app object, anyone can get it using AfxGetApp if they want to. You dont have to export your class if its derived from CWinApp. Use an MFC Extension DLL to do this. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Murrgon" <murrgon@hotmail.com> wrote in message news:eh7AHxqxEHA.1300@...

Pump messages while waiting
In some parts of my code I EnterCriticalSection which may stop the message pump. For the time being there's no code that would SendMessage from critical section, so there's no deadlock, but I would like to prevent future headaches and handle SendMessage-from-CS situations. For this I probably have to use mutex and MsgWaitForSingleObject, but what should I do when some message arrives? The important thing is that the code is in the class that may be used in both the MFC and non-MFC projects. Mihajlo Cvetanovic wrote: >In some parts of my code I EnterCriticalSection which m...

WM_ERASEBGND not caught by CWinApp::PreTranslateMessage
Hi, I am having a problem with a handler for WM_ERASEBGND and wanted to intercept WM_ERASEBGND in an overriden CWinApp::PreTranslateMessage. However, for some reason, WM_ERASEBGND is NEVER received in PreTranslateMessage!! Am I doing something wrong? -- Thanks in advance, Juan Dent, M.Sc. Juan Dent wrote: > Hi, > > I am having a problem with a handler for WM_ERASEBGND and wanted to > intercept WM_ERASEBGND in an overriden CWinApp::PreTranslateMessage. > However, for some reason, WM_ERASEBGND is NEVER received in > PreTranslateMessage!! > Am I doing something wrong...