winrt/base.h parsing errors when compiling c++ projects with c++/WinRT

Hi,

I am new to UE as well as c++. Recently I have implemented a custom BLE client using c++/WinRT and successfully tested it in a standalone console app. When I began porting the core logic over to UE5.4.3 as a UActorComponent under a UE c++ project, I encountered the following error:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\cppwinrt\winrt\base.h(261): error C4668: '_M_IX86' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'

After a great deal of trial and error, I stumbled onto a “solution”; it appears that if I added an additional #include "Windows/PreWindowsApi.h", I am able to bypass this error and eventually getting the code to compile. This header file was never needed in the standalone console app I successfully tested, I am curious why it’s needed when compiling with UE5.

I was able to resolve winrt compilation issues by doing the following:

  1. Sandwich all winrt header includes between:
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/PreWindowsApi.h"

... winrt or windows headers....

#include "Windows/PostWindowsApi.h"
#include "Windows/HideWindowsPlatformAtomics.h"
#include "Windows/HideWindowsPlatformTypes.h"
  1. Regenerate winrt headers with latest version of cppwinrt.exe.
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.