When compiling the sample codes below taken from Cprogramming using a Dev-C++ compiler, there are errors,?
anonymous
1970-01-01 00:00:00 UTC
When compiling the sample codes below taken from Cprogramming using a Dev-C++ compiler, there are errors,?
Three answers:
Cubbi
2011-04-25 11:04:27 UTC
The compiler is complaining at the use of the keyword NULL for arguments that are not pointers: the first argument of CreateWindowExA(), which is supposed to be a DWORD, the 3rd and 4th arguments of PeekMessageA(), which are supposed to be UINTs.
While technically legal C++ (NULL is an expression that evaluates to an integral zero, and zero is a valid value for both UINT and DWORD), it's counter-intuitive, since NULL was used to indicate the null pointer in C and earlier C++, so the programmer is saying "null pointer", while the function wants a number. Change those instances of NULL to literal zero and the warning should go away.
Alternatively, you can turn this warning off with the compiler argument -Wno-conversion-null
Little Princess
2011-04-25 08:13:38 UTC
You need to change the third and fourth parameters in your call to PeekMessage to something that's legitimate (non-NULL).
?
2011-04-25 01:16:27 UTC
### LATEST ANSWER ###
THIS is THE SOLUTION. Put the following two lines before all other includes in your StdAfx.h
#define WIN32_LEAN_AND_MEAN
#include
And remove them from your cpp file.
Does it work now?
If it doesn't I am afraid there is something terribly wrong with Dev-C++ compiler, which I guess is very improbable, as it is a very good compiler.
Hope that helps!
.....................
# PREVIOUS ANSWER #
Your code compiled perfectly on my MSVC++ 6 compiler, when I commented out "StdAfx.h" inclusion.
It seems there is something in your "StdAfx.h" that is interfering with the declarations in windows.h. But that is just a guess. Before pointing fingers at Dev-C++ compiler, I would definitely like to see the contents of your "StdAfx.h" file.
Can you post it here?
#Comment for those who may wonder how i was able to compile so easily!
Simply copy paste of above source will not work. You may encounter some illegal characters, some missing brackets, and one or two incomplete variable names. You can use your common sense. On the "TextOut" line the missing variable name is "string".
@Jay - While posting code, please try to ensure you can copy back correctly, i.e. the posted code is same as the original code, except for the whitespace. Sometimes. characters at the end of a long line get lost. Use the "Preview" functionality to check if it is indeed what you expect to post.
Hope that helps!
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.