If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

In general, whenever you process a message, you must return what is documented that you return for the particular message. Don't guess, don't leave the return empty, etc. You are to return 0 if you process the WM_PAINT message.

3)

Code:

#ifndef UNICODE
#define UNICODE
#endif

Why are you doing this? The build settings already have these preprocessor constants defined for you.

Re: starter app not responding

Thanks paul for your suggestions,

1. adding a return statement did not solve the problem.
2.comparing with example code in msdn, difference is i used LPMSG and did not use & when passing to translate and dispatch functions in message loop while example uses MSG type and use & in those functions as they need pointer.

if you look in the function definition both functions needs their argument to be LPMSG type, so why program crashes if i use LPMSG in message loop?

as beginner i would ignore it, but i fear i would keep accumulating such things which can make writing stable programs more difficult.

The two snippets differ drastically. In first case pointer variable being used actually points to no really allocated memory. Writing to unallocated memory results in crash in your case. I would say you're lucky to have this crashed, as the garbage pointer might accidentally point to an allocated memory, which is going to be just corrupted by the write operation.

Second snipped has a real MSG structure allocated on stack and allowed for writing. This way all write operations deal with valid memory region, and further reads will be done from this known memory.

The main lesson you should learn from this: making the code be just compilable without complying to real physical meaning of the construct is not enough to make your program run correctly. Code may compile successfully being at the same time physically senseless or even harmful.

Another lesson learned is: You cannot write program in C/C++ having no idea of how language constructs correspond to physical computer architecture.

Lesson to be learned later: You cannot write any relatively complex program for some OS having no idea of OS architecture and physical specifics of its implementation.

Re: starter app not responding

But it corrected another problem, and that is the return of a garbage value back to the OS.

2.comparing with example code in msdn, difference is i used LPMSG and did not use & when passing to translate and dispatch functions in message loop while example uses MSG type and use & in those functions as they need pointer.

You made a mistake that a lot of beginner C/C++ programmers make, and that mistake is believing that if a function requires a pointer, you must declare a pointer and give it to the function.

When a function requires a pointer, that function is actually asking you to provide the address of an existing variable. That is how C and C++ prototype and document functions that require an address -- pointer parameters are used to denote this.

So you provided an uninitialized pointer to the function, and what do you think happens when you pass an uninitialized pointer to a function? First, there is no function in the world of C++ that can take a passed in uninitialized pointer and do anything with it that's safe. Second, since the function assumed that the pointer you passed actually points to a valid location, it goes and attempts to write to that location, so you get the crash.

The other extreme of this mistake is declaring a pointer, calling malloc() or "new" to allocate memory, and then passing that pointer. Even though this may work, it's dumb -- it slows the code down, possibly introduces a memory leak, and honestly, looks amateurish and unprofessional to a seasoned C/C++ programmer.

Regardless, whenever a function requires a pointer, it is asking for an address of something that exists. Passing uninitialized pointers, or declaring a pointer, needlessly allocating memory, and then passing that pointer are both mistakes in not understanding how C/C++ works with respect to prototyping functions.

Re: starter app not responding

Originally Posted by pavankn18

Thank you sir i got it.

adding a line Msg = new MSG; do make the program stable, will try to be careful
feeling really nice now

No.

Read my post carefully. Why are you calling "new"? You have now made both mistakes that I mentioned. You are now calling the allocator for no reason whatsoever, and also you probably introduced a memory leak.

Variable must have some solid reason to be allocated on heap. Typically the reason is that variable lifespan must extend beyond function scope where it was created. Definitely not your case. Besides, explicit use of new requires for explicit delete, which makes such sort of allocation be prone to leaking.

Re: starter app not responding

Thank you,

please help me with the following,

1.when i write a function with a return type and no return value it will result in compile time error, but why compiler did not complain
anything in windowsproc? compiler wont tell anything even in case of int main with no return statement.

2.what is the actual return type of windowsproc? LRESULT has definition #define LONG_PTR LRESULT, further #define _w64 LONG_PTR.
what is _w64? how shall i interpret it?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.