473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Whats the difference between while loop in Windows message loop and while(1)

I am trying to register my interface with IConnectionPoint of outlook
reminders to capture some Outlook Reminder events and having some
issues. Here goes the pseudo code

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//Register class CMyEventHandler : public IDispatch with
IConnectionPoint of Outlook reminder

//Removed Wizard generated code for registering the widow class and
initializing the window

// And Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

If this is the code I do get control back in CMyEventHandler::Invoke()
when some Reminder event occurs as a notification from outlook.

But if I replace the message loop with while(1){} I dont get any such
notifications, instead outlook hangs.

Looking at the Main message loop, it seems that its also a infinite
loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
is why i dont get notified by Outlook if there is actual infinite loop
instead of message loop? What make message loop different than
while(1){} ?

Thanks in advance

Dec 11 '06 #1
4 2845

Uday Bidkar wrote:
I am trying to register my interface with IConnectionPoint of outlook
reminders to capture some Outlook Reminder events and having some
issues. Here goes the pseudo code

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//Register class CMyEventHandler : public IDispatch with
IConnectionPoint of Outlook reminder

//Removed Wizard generated code for registering the widow class and
initializing the window

// And Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

If this is the code I do get control back in CMyEventHandler::Invoke()
when some Reminder event occurs as a notification from outlook.

But if I replace the message loop with while(1){} I dont get any such
notifications, instead outlook hangs.

Looking at the Main message loop, it seems that its also a infinite
loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
is why i dont get notified by Outlook if there is actual infinite loop
instead of message loop? What make message loop different than
while(1){} ?

Thanks in advance
None of the above is C++. Please post your question in a relevent
newsgroup that deals with that particular operating system.
[5.9] Which newsgroup should I post my questions?
http://www.parashift.com/c++-faq-lite/how-to-post.html

Dec 11 '06 #2
Uday Bidkar wrote:
while (GetMessage(&msg, NULL, 0, 0))
But if I replace the message loop with while(1){} I dont get any such
notifications, instead outlook hangs.
Looking at the Main message loop, it seems that its also a infinite
loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
is why i dont get notified by Outlook if there is actual infinite loop
instead of message loop? What make message loop different than
while(1){} ?
The main difference is that '1' is not the same as 'GetMessage (....)'.
Thinking a bit, the name 'GetMessage' suggests that it gets a message, so
the difference is that with 'while (1)' you never get a message. The next
logical step is to read something about Windows messages.

--
Salu2
Dec 11 '06 #3
Thanks Julián for responding.

The documentation for GetMessage say that if the function retrieves a
message other than WM_QUIT, the return value is nonzero and if the
function retrieves the WM_QUIT message, the return value is zero. This
means that while (GetMessage(&msg, NULL, 0, 0)) is same as while(1)
unless WM_QUIT is the message retrieved from message queue so why the
difference in behavior?

I apologize for posting this in wrong newsgroup.

Dec 12 '06 #4
Uday Bidkar wrote:
The documentation for GetMessage say that if the function retrieves a
message other than WM_QUIT, the return value is nonzero and if the
function retrieves the WM_QUIT message, the return value is zero. This
means that while (GetMessage(&msg, NULL, 0, 0)) is same as while(1)
unless WM_QUIT is the message retrieved from message queue so why the
difference in behavior?
The difference is that '1' does nothing with 'msg'
but 'GetMessage(&msg, ...' does something with it. Read about Windows
messages in any article, book or help file about Windows programming.

If you come from some functional programming language, forget all about "no
secondary effects".

--
Salu2
Dec 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
3
by: RobG | last post by:
A little while ago I opined that do/while loops are harder to read than for loops, and therefore I preferred using for loops. However, it was pointed out that do/while has significant...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
21
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c...
8
by: buc | last post by:
I have a simple combox on the screen that is bound via a datareader to a stored proc in sql that returns a simple string. The code is 'load stored proc then dReader =...
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
10
by: rohitjogya | last post by:
Can anyone tell me the difference bet for loop and while loop execution? ____________________ for (i=0 ; i<10 ; i++) ; /* Do nothing*/ print i; ___________________ i=0;
26
by: Muzammil | last post by:
whats the beauty of "malloc" over "new" why its helpful for programmer.for its own memory area.??
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.