question

Crush3dice-6030 avatar image
0 Votes"
Crush3dice-6030 asked Crush3dice-6030 commented

Suddenly douzens of errors using windows.h

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.

c++vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GuidoFranzke avatar image
0 Votes"
GuidoFranzke answered Crush3dice-6030 commented

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





· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your reply.

It happened when i was debugging my code. The mentioned line was the only thing i changed, because i was not sure weither the printed address was formatted or not. It could ofcourse be that i accidently clicked a hotkey but if so that would have been accidentally and i would not know now.

  1. The include order is exactly the same as before. This is 100% unchanged. As expected, changing the order did not change the behavior unfortunately.

  2. When i had the problem with cout i was using std::cout.

  3. I started with an empty project but use std::cout to print to the console.

  4. This surely works and reduces the errors thrown to only 67 and none of them directly in my files. But still i get weird errors like in the following typedef from minwindef.h
    typedef DWORD near *PDWORD;
    which says: ";" missing in front of "*".

0 Votes 0 ·

Also worth mentioning. Every project that includes windows.h throws the same errors. Even if i make a new one.

regards, Frederick

0 Votes 0 ·

If possible, show your full new project (on OneDrive, GitHub, etc.).

You can also right-click the #include statement, then “Go To Document <Windows.h>”. It should not be empty or truncated.

0 Votes 0 ·
Show more comments