Suddenly douzens of errors using windows.h

Crush3dice 1 Reputation point
2021-03-08T12:39:55.417+00:00

Hello,

i recently started out using visual studio c++ on my windows 10 machine because i wanted to code on the WINAPI. Unfortunately i noticed a weird behavior of MSVC++. I had my code compiling running perfectly with windows.h included. Now the exact thing i did to cause the weird behavior is changing the line:

cout << "entry: " << hex << (DWORD)((parameters*)loaderDest + 1) << endl;

to

cout << "entry: " << hex << (PVOID)((parameters*)loaderDest + 1) << endl;

and then back again. Suddenly i got 1144 Errors. They seem to be somewhat related to the typedefs in windows.h. For example suddenly hovering over DWORD gives

typedef <error-type> DWORD(<error-type>).

I don't understand this syntax but watching other error messages it seems like DWORD is interpreted as a function. If i go to the typedef it jumps to

typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);

Now last time i had a very similar problem when including stdio.h and then again removing it. That time i got douzens of errors when including <iostream> and i ended up simply uninstalling and installing MSVC++ which fixed it. But since this problem seems to reappear i wanted to ask what causes this behavior? Could it be that MSVC++ sometimes adds #defines to my file which alter the behavior of windows.h?

Tanks for help.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,760 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Guido Franzke 2,196 Reputation points
    2021-03-08T13:12:41.127+00:00

    Hello,
    I'm sorry I cannot reproduce your problem. I think you must have done more than only change the line and change it back.

    Nevertheless I remember I had questionable errors with windows.h before too. The errors resulted because of other include files or a special project type.
    You could try the following:

    1. change the order of #include
    2. for cout, do you use the standard library std::cout or the "old" cout - I've seen differences there too. Search for using namespace std for example. When you use cout, it can be different from std::cout. Define cout explicitly.
    3. What kind of project do you use in VS? As far as I remember, there can be differences between a console app and a GUI MFC app (e.g. in MFC you don't include windows.h by yourself, you should VS handle the include).
    4. change DWORD to unsigned long.

    Regards, Guido


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.