electronicarts / CnC_Remastered_Collection

Other
18.31k stars 4.74k forks source link

Windows headers require the default packing option. Changing this can lead to memory corruption. #34

Open Life4gal opened 4 years ago

Life4gal commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 https://github.com/electronicarts/CnC_Remastered_Collection/issues/36