keywords:UE4, error C3668, windows.h, _InterlockedIncrement, UpdateResourceW, none of the 4 overloads could convert all the argument types

Issue:

Compilcation Error in v4.24:

F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(33): error C2665: 'FWindowsPlatformAtomics::_InterlockedIncrement': none of the 4 overloads could convert all the argument types
F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(36): note: could be 'int64 FWindowsPlatformAtomics::_InterlockedIncrement(volatile int64 *)'
F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(31): note: or       'int32 FWindowsPlatformAtomics::_InterlockedIncrement(volatile int32 *)'
F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(26): note: or       'int16 FWindowsPlatformAtomics::_InterlockedIncrement(volatile int16 *)'
F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(21): note: or       'int8 FWindowsPlatformAtomics::_InterlockedIncrement(volatile int8 *)'
F:\UE_4.24\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(33): note: while trying to match the argument list '(long *)'

Compilcation Error in v4.19:

2>F:\EpicGames\UE_4.19\Engine\Source\Runtime\Engine\Classes\Engine/TextureCube.h(69): error C3668: 'UTextureCube::UpdateResourceW': method with override specifier 'override' did not override any base class methods
2>F:\EpicGames\UE_4.19\Engine\Source\Runtime\Engine\Classes\Engine/CanvasRenderTarget2D.h(43): error C3668: 'UCanvasRenderTarget2D::UpdateResourceW': method with override specifier 'override' did not override any base class methods

Compilcation Error in v4.18:

2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(67): error C2039: '_InterlockedIncrement': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(67): error C2665: '_InterlockedIncrement': none of the 4 overloads could convert all the argument types
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8844): note: could be 'unsigned __int64 _InterlockedIncrement(volatile unsigned __int64 *)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8833): note: or       'unsigned long _InterlockedIncrement(volatile unsigned long *)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8824): note: or       'unsigned int _InterlockedIncrement(volatile unsigned int *)'
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\intrin.h(259): note: or       'long _InterlockedIncrement(volatile long *)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(67): note: while trying to match the argument list '(volatile int64 *)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(79): error C2039: '_InterlockedAdd': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(79): error C2664: 'LONG _InterlockedAdd(volatile LONG *,LONG)': cannot convert argument 1 from 'volatile int64 *' to 'volatile LONG *'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(79): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(90): error C2039: '_InterlockedDecrement': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(90): error C2665: '_InterlockedDecrement': none of the 4 overloads could convert all the argument types
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8875): note: could be 'unsigned __int64 _InterlockedDecrement(volatile unsigned __int64 *)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8864): note: or       'unsigned long _InterlockedDecrement(volatile unsigned long *)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8855): note: or       'unsigned int _InterlockedDecrement(volatile unsigned int *)'
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\intrin.h(209): note: or       'long _InterlockedDecrement(volatile long *)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(90): note: while trying to match the argument list '(volatile int64 *)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(102): error C2039: '_InterlockedAdd': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(102): error C2664: 'LONG _InterlockedAdd(volatile LONG *,LONG)': cannot convert argument 1 from 'volatile int64 *' to 'volatile LONG *'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(102): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(114): error C2039: '_InterlockedExchange': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(114): error C2665: '_InterlockedExchange': none of the 4 overloads could convert all the argument types
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8910): note: could be 'unsigned __int64 _InterlockedExchange(volatile unsigned __int64 *,unsigned __int64)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8898): note: or       'unsigned long _InterlockedExchange(volatile unsigned long *,unsigned long)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8888): note: or       'unsigned int _InterlockedExchange(volatile unsigned int *,unsigned int)'
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\intrin.h(222): note: or       'long _InterlockedExchange(volatile long *,long)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(114): note: while trying to match the argument list '(volatile int64 *, int64)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(125): error C2039: '_InterlockedExchange': is not a member of 'FWindowsPlatformAtomics'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformAtomics.h(14): note: see declaration of 'FWindowsPlatformAtomics'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(125): error C2665: '_InterlockedExchange': none of the 4 overloads could convert all the argument types
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8910): note: could be 'unsigned __int64 _InterlockedExchange(volatile unsigned __int64 *,unsigned __int64)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8898): note: or       'unsigned long _InterlockedExchange(volatile unsigned long *,unsigned long)'
2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winbase.h(8888): note: or       'unsigned int _InterlockedExchange(volatile unsigned int *,unsigned int)'
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\intrin.h(222): note: or       'long _InterlockedExchange(volatile long *,long)'
2>f:\epicgames\ue_4.18\engine\source\runtime\core\public\HAL/ThreadSafeCounter64.h(125): note: while trying to match the argument list '(volatile int64 *, int)'
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Engine\Classes\Engine/TextureCube.h(69): error C3668: 'UTextureCube::UpdateResourceW': method with override specifier 'override' did not override any base class methods
2>F:\EpicGames\UE_4.18\Engine\Source\Runtime\Engine\Classes\Engine/CanvasRenderTarget2D.h(43): error C3668: 'UCanvasRenderTarget2D::UpdateResourceW': method with override specifier 'override' did not override any base class methods

Caused by:
Maybe there are some third party libraries that using Windows API were linked in your game, and these libraries are conflicted with Windows SDK which your codes (e.g. using CreateMutex() of VC++, not std::mutex of STL) dependented on in local environment.

Solution:
On Unreal Forums, there is a saying: include following headers in MyProject.h in your game.

#include "UMG.h"
#include "UMGStyle.h"
#include "Slate/SObjectWidget.h"
#include "IUMGModule.h"
#include "Blueprint/UserWidget.h"

Reference:
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/113028-getting-build-error-in-my-engine-plugin-while-building-in-ue4-editor-while-packaging-the-project

But sometimes it doesn’t work even these headers included, the silver bullet is to replace Windows API with cross platform libraries (e.g. STL) in your game, e.g. instead of CreateMutex() with std::mutex, or make sure third party libraries didn’t link Windows libraries statically, but rather linking dynamically.


一切鬼魂们的叫唤无不低微,然有秩序,与火焰的怒吼,油的沸腾,铜叉的震颤和鸣,造成醉心的大乐,布告三界:地下太平。──鲁迅《失掉的好地狱》