SAPI (or other users of atlmfc) in UE4 with VS2017/2019

How to use Microsoft Speech API (SAPI) in Unreal Engine 4 (UE4), with Visual Studio 2017 Community Edition. Because I’m always forgetting it.

There are 4 things to do:

1. Add MFC/ATL support in Visual studio installer.

2. Include SAPI headers:

#include "AllowWindowsPlatformTypes.h"
#pragma warning(push)
#pragma warning(disable: 4191)
#pragma warning(disable: 4996)
#ifndef DeleteFile
#define DeleteFile DeleteFileW
#endif
#ifndef MoveFile
#define MoveFile MoveFileW
#endif
#ifndef LoadString
#define LoadString LoadStringW
#endif
#ifndef InterlockedDecrement
#define InterlockedDecrement _InterlockedDecrement
#endif
#ifndef InterlockedIncrement
#define InterlockedIncrement _InterlockedIncrement
#endif
#ifndef GetMessage
#define GetMessage GetMessageW
#endif

#include “sapi.h”
#include “sphelper.h”


#undef DeleteFile
#undef MoveFile
#undef LoadString
#undef InterlockedDecrement
#undef InterlockedIncrement
#undef GetMessage
#pragma warning(pop)
#include "HideWindowsPlatformTypes.h"

3. Additional include folders:

Steps 3 and 4 are needed if you are getting errors about atlbase.h not being found.

Projects Properties::VC++ Directories::Include directories add the folder where atlbase.h is located, like:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\atlmfc\include

4. Add atl libs folder

Projects Properties::VC++ Directories::Library Directories, add:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\atlmfc\lib

Alternatively you can also add this to the Build.cs (in this case I copied the atls.lib file into my project folder):

PublicAdditionalLibraries.Add(@"D:/Users/Stan/Documents/UnrealProjects/MyProject/Plugins/SAPI_Plugin/Binaries/Win64/atls.lib");

If you know better way let me know.

Tags:,
3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *