Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
Root cause:
This is because it contains some header files that windows. H already contains, such as “fileapi. H” and “winuser. H”, but it does not contain windows. H
or
it contains “fileapi. H” and “winuser. H” first, and then contains windows. H, which is not in the right order
Let’s start with the solution:
just add include “windows. H” to the code, or adjust the order and put winows. H in front of it or
Online solutions:
Add to project_ AMD64_ Macro (the other three can also be used) can also solve the problem
specific method: right click the project name — > Attribute — > C/C++–> Preprocessor — > Add a macro as follows:
specific process:
When I call the shellexecute function, I will prompt the error “no target architecture”. The code is simplified as follows:
#include "stdafx.h"
#include "WinUser.h"
#include <ShellAPI.h>
int main()
{
ShellExecute(0, NULL, L"http://www.baidu.com", NULL, NULL, SW_SHOWNORMAL);
return 0;
}
The location error is in WinNT. H
#if defined(_AMD64_) || defined(_X86_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif defined(_IA64_) || defined(_ARM_) || defined(_ARM64_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif !defined(RC_INVOKED)
#error "No Target Architecture"
#endif
The reason is that there is no definition of (_ AMD64_) 、(_ X86_) When the compiler detects these macros, it throws an exception
When shellexecute is called, SW_ Show normal prompt can’t be found, check, SW_ Shownormal is defined in “winuser. H”, so “include” winuser. H “
“Winuser. H” defines all API exported by user32.dll and various macro definitions, such as WM representing message ID_* Macro, most of the APIs related to windows UI are defined in winuser. H. This file is included in windows. H
So it’s usually direct include & lt; windows.h> As mentioned above (_ AMD64_) 、(_ X86_) It was also defined in windows. H first, so an error was reported
In this case, winuser and & lt; ShellAPI.h> Can be deleted, including a windows. H can be directly
What are the important header files in windows. H:
Windows. H is one of the most important header files. It contains other windows header files, some of which also contain other header files. The most important and basic of these header files are:
Windef. H basic data type definition
WinNT. H supports Unicode type definition
winbase. H kernel function
winuser. H user interface function// in this example, shellexecute is defined here
wingdi. H graphic device interface function
Similar Posts:
- [Solved] VS winsock.h and ws2def.h a large number of redefined error
- undefined reference to ‘WinMain@16’
- About the compilation error “dereferencing pointer to incomplete type
- Error: expected identifier before numeric constant [Solved]
- Small function: dynamic change of scripting define symbols (macro definition) by unity
- Invalid use of incomplete type struct or class solution
- fatal error C1010: unexpected end of file while…
- Latex Error: Misplaced alignment tab character & [How to Solve]
- [Solved] Cannot Open “gl/glut.h” File Error: No such file or directory