Windows headers require the default packing option changing this can lead to memory corruption

When I’m trying to compile my C++ project in Visual Studio, I keep getting the 2 following errors:

E1574: Static assertion failed with "Windows headers require the default 
packing option. Changing this can lead to memory corruption. This diagnostic 
can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined."

and

C2338: Windows headers require the default packing option. Changing this can 
lead to memory corruption. This diagnostic can be disabled by building with 
WINDOWS_IGNORE_PACKING_MISMATCH defined.

I think the issue has to be something in my Visual Studio settings, cause the project compiles fine on my other PC, and I just installed Visual Studio on this PC.

From doing some searches look like the issue stems from a mismatch of Windows packages, however when installing Visual Studio I tried to install all the C++ and Windows 10 modules I saw.

Also, I’m only including windows.h in order to use ShellExecute(), so if there’s a better way to use ShellExecute() I’m open to that. Thanks!

asked Jun 12, 2019 at 21:35

code4days's user avatar

8

As 1201ProgramAlarm mentioned above, the solution was disabling the /Zp (structure packing) compiler option.

answered Sep 30, 2019 at 18:07

code4days's user avatar

code4dayscode4days

6013 gold badges9 silver badges17 bronze badges

3

If others arrive at this question (like I did), the underlaying issue is, bar the project compiler options doing it as per the comment by
code4days, possibly that some source file or header is fiddling with the struct packing size before the windows.h is included.

In your sources and headers, look for

#pragma pack(push, ... 

If you can, move this to where the structs are actually defined and move the corresponding #pragma pack(pop) under the stucts.

In any case, by not having that #prama pack(push, 1) just before the windows.h include fixed the compiler error for me.

answered Sep 12 at 10:57

Meirion Hughes's user avatar

Meirion HughesMeirion Hughes

25.2k12 gold badges72 silver badges123 bronze badges

When I’m trying to compile my C++ project in Visual Studio, I keep getting the 2 following errors:

E1574: Static assertion failed with "Windows headers require the default 
packing option. Changing this can lead to memory corruption. This diagnostic 
can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined."

and

C2338: Windows headers require the default packing option. Changing this can 
lead to memory corruption. This diagnostic can be disabled by building with 
WINDOWS_IGNORE_PACKING_MISMATCH defined.

I think the issue has to be something in my Visual Studio settings, cause the project compiles fine on my other PC, and I just installed Visual Studio on this PC.

From doing some searches look like the issue stems from a mismatch of Windows packages, however when installing Visual Studio I tried to install all the C++ and Windows 10 modules I saw.

Also, I’m only including windows.h in order to use ShellExecute(), so if there’s a better way to use ShellExecute() I’m open to that. Thanks!

asked Jun 12, 2019 at 21:35

code4days's user avatar

8

As 1201ProgramAlarm mentioned above, the solution was disabling the /Zp (structure packing) compiler option.

answered Sep 30, 2019 at 18:07

code4days's user avatar

code4dayscode4days

6013 gold badges9 silver badges17 bronze badges

3

If others arrive at this question (like I did), the underlaying issue is, bar the project compiler options doing it as per the comment by
code4days, possibly that some source file or header is fiddling with the struct packing size before the windows.h is included.

In your sources and headers, look for

#pragma pack(push, ... 

If you can, move this to where the structs are actually defined and move the corresponding #pragma pack(pop) under the stucts.

In any case, by not having that #prama pack(push, 1) just before the windows.h include fixed the compiler error for me.

answered Sep 12 at 10:57

Meirion Hughes's user avatar

Meirion HughesMeirion Hughes

25.2k12 gold badges72 silver badges123 bronze badges

Hey guys!

I’ve been working on an AE plugin, and I had a really strange problem today. I’ve never had a problem building/debugging the plugin, but today when I tried to debug in Visual Studio I got this error message:

——

Severity Code Description Project File Line Suppression State
Error (active) E1574 static assertion failed with «Windows headers require the default packing option. Changing this can lead to memory corruption. This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined.» Skeleton C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h 2482

——

After some googling, I found this stack overflow post and tried following their advice but it didn’t help. I also tried defining «WINDOWS_IGNORE_PACKING_MISMATCH» in C/C++ > Preprocessor > Preprocessor Definitions but that didn’t do anything either.

Does anyone know why this would’ve randomly started happening? Did I perhaps adjust a setting in my IDE without realizing it…? Any and all ideas would be greatly appreciated.

Thanks!

@Life4gal

winnt.h
// Much of the Windows SDK assumes the default packing of structs. #if !defined(WINDOWS_IGNORE_PACKING_MISMATCH) && !defined(__midl) && !defined(MIDL_PASS) && !defined(SORTPP_PASS) && !defined(RC_INVOKED) #if defined(__cplusplus) && (_MSC_VER >= 1600) static_assert(__alignof(LARGE_INTEGER) == 8, "Windows headers require the default packing option. Changing this can lead to memory corruption." " This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined."); #elif _MSC_VER >= 1300 #pragma warning(push) #pragma warning(disable: 4116) C_ASSERT(TYPE_ALIGNMENT(LARGE_INTEGER) == 8); #pragma warning(pop) #endif #endif

«Windows headers require the default packing option. Changing this can lead to memory corruption.» » This diagnostic can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined’

Project Settings > C/C++ > Code Generation > Struct Member Alignment (change to Default)

I hope it works for you. : -)

@alexlk42

In my experience you are better off defining WINDOWS_IGNORE_PACKING_MISMATCH instead of setting struct member alignment to default. The altered struct alignment was causing my dlls to crash the game. Preserving the original struct alignment resulted in dlls that were compatible with the game. My fork shows how to do this if you are interested https://github.com/alexlk42/CnC_Remastered_Collection

@Bast75

Hi Alexlk42,
I downloaded your version. But when i build, it got the following error:

Resource\TiberianDawn.rc(10): fatal error RC1015: cannot open include file ‘afxres.h’.

Done building project «TiberianDawn.vcxproj» — FAILED.
—— Build started: Project: RedAlert, Configuration: Release Win32 ——
Resource\RedAlert.rc(10): fatal error RC1015: cannot open include file ‘afxres.h’.

Done building project «RedAlert.vcxproj» — FAILED.
========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========

afxres.h is indeed missing.
Any ideas?

@alexlk42

I believe that means you need to download the build tools, which contain the needed headers.

Downloaded v142 build tools (C++ MFC) via Visual Studio Installer.

This is discussed here #36

Epic Developer Community Forums

Loading

  • Windows hello пин код как узнать
  • Windows hosts file windows 7 x64
  • Windows had encounter a problem
  • Windows hdr calibration win 10
  • Windows generate ssh key for git