# Errors when including winscard.h

**URL:** <https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [December 29, 2022, 8:04pm UTC](https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484 "2022-12-29T20:04:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevinVRay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KevinVRay](https://forums.unrealengine.com/u/KevinVRay)\
**Post date:** [December 29, 2022, 8:04pm UTC](https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484/1 "2022-12-29T20:04:36Z")

</div>

Hi All, Im after some advice.

Im trying to connect a cardreader to our UE4.27 project, the SDK for the cardreader uses.

winscard.h

When i import it the following compile errors

C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h(584): warning C4005: ‘TEXT’: macro redefinition  
C:\Program Files\Epic Games\UE\_4.27\Engine\Source\Runtime\Core\Public\HAL/Platform.h(1085): note: see previous definition of ‘TEXT’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7542): error C4668: ‘\_WIN32\_WINNT\_WIN10\_TH2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7548): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS1’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7553): error C4668: ‘\_WIN32\_WINNT\_WIN10\_TH2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7557): error C4668: ‘\_WIN32\_WINNT\_WIN10\_TH2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7564): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7574): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7578): error C4668: ‘\_WIN32\_WINNT\_WIN10\_TH2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7583): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS3’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(7777): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(12249): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS3’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(12266): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS3’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(12285): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS2’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’  
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winioctl.h(12404): error C4668: ‘\_WIN32\_WINNT\_WIN10\_RS3’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’

After some searches have tried

> [@Compile errors updating from 4.26.2 to 4.27.2](https://forums.unrealengine.com/t/compile-errors-updating-from-4-26-2-to-4-27-2/267070):
>
> Just trying to update my project to use 4.27.2. I downloaded the editor version and tried to open my project with it. It showed a popup asking me to rebuild binaries, when I said yes, it said there was errors and I have to rebuild myself from source. Went into Rider, tried to build, I got a bunch of errors about missing precompiled flags. The only way I was able to build is to include those flags in my Build.cs ApexDefs.h(54): [C4668] 'USE\_RTTI' is not defined as a preprocessor macro, replac…

> [@Issue with macro redefinition](https://forums.unrealengine.com/t/issue-with-macro-redefinition/108234/2):
>
> Did you ever figure out how to solve this? Thank you

> [@Compilation error while migration from 4.26.2 to 4.27.0](https://forums.unrealengine.com/t/compilation-error-while-migration-from-4-26-2-to-4-27-0/487863/3):
>
> I’m having the same problem, where did you add the #define?

so i have  
#ifdef TEXT  
#undef TEXT // Delete macro UE4  
#endif  
#include \<winscard.h\>  
#ifdef TEXT  
#undef TEXT // Delete macro Win32  
#endif  
#define TEXT(quote) \_\_ TEXT(quote) // Define macro UE4

and in my build.cs file

new string  
{  
“\_WIN32\_WINNT\_WIN10\_TH2”,“\_WIN32\_WINNT\_WIN10\_RS1”,  
“\_WIN32\_WINNT\_WIN10\_RS2”,  
“\_WIN32\_WINNT\_WIN10\_RS3”,  
“\_WIN32\_WINNT\_WIN10\_RS4”,  
“\_WIN32\_WINNT\_WIN10\_RS5”  
}  
);

so now it compiles with an empty file but when i do anything like

bool UACSCardReader::EstablishContext()  
{  
retCode = SCardEstablishContext(SCARD\_SCOPE\_USER,NULL,NULL, &hContext);  
if (retCode != SCARD\_S\_SUCCESS)  
{  
return false;  
}  
else  
{  
return true;  
}  
}

it throws this error

ACSCardReader.cpp.obj : error LNK2019: unresolved external symbol SCardEstablishContext referenced in function “public: static bool \_\_cdecl UACSCardReader::EstablishContext(void)” (?EstablishContext@UACSCardReader@@SA\_NXZ)

Am i missing something or doing something stupid

The only other option i can think of using WinSCard.dll using FPlatformProcess::GetDllHandle and using FPlatformProcess::GetDllExport to get the methods

I have done this before to connect to other hardware to connect to a plc and usb devices, however in this situation i would prefer to find a solution to use #include \<winscard.h\>

Thanks

---

<div class="post-metadata">

**Author:** ![KevinVRay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KevinVRay](https://forums.unrealengine.com/u/KevinVRay)\
**Post date:** [January 15, 2023, 4:07pm UTC](https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484/2 "2023-01-15T16:07:26Z")

</div>

OK i have started with the DLL exporting but i’m having issues

When i play i now get a message every time i stop it saying.

“source2 warning”  
“Only one instance of the game can be running at one time”

this happens in editor or after a build.

also im tring to FPlatformProcess::GetDllExport the function  
[SCardConnectW function (winscard.h) - Win32 apps | Microsoft Learn](https://learn.microsoft.com/en-gb/windows/win32/api/winscard/nf-winscard-scardconnectw)

i currently get Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION 0x0000000000000000 when i run it which normally means i have screwed something up in the reference i have change what i have written so many times, i will tidy it up and post it, but any advice would be good.

---

<div class="post-metadata">

**Author:** ![timmy6845](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@timmy6845](https://forums.unrealengine.com/u/timmy6845)\
**Post date:** [April 27, 2023, 3:23pm UTC](https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484/3 "2023-04-27T15:23:22Z")

</div>

Yeah, this is a necro - but recently had to do this for a project and this is one of the first things that pops up in search engines so wanted to post an answer.

In order to include winscard on Windows, you’ll need to add an additional library from the Windows SDK in your build.cs. Once you do that you can include winscard.h as a third party include and your all set.

In build.cs add:

```auto
PublicAdditionalLibraries.Add(Path.Combine(Target.WindowsPlatform.WindowsSdkDir,
                                        "Lib",
                                        Target.WindowsPlatform.WindowsSdkVersion,
					"um/x64", // Probably a way to get this dynamically, but I didn't bother since it's a short run one off.
					"winscard.lib"));

```

in your cpp add:

```auto
THIRD_PARTY_INCLUDES_START
#include <winscard.h>
THIRD_PARTY_INCLUDES_END

```

Once that’s in place the UnrealBuildTool will pull the library in, and you should be all set. I did this for blueprint library plugin recently and it worked well enough.

---

<div class="post-metadata">

**Author:** ![KevinVRay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KevinVRay](https://forums.unrealengine.com/u/KevinVRay)\
**Post date:** [August 7, 2023, 9:26am UTC](https://forums.unrealengine.com/t/errors-when-including-winscard-h/738484/4 "2023-08-07T09:26:13Z")

</div>

Sorry to reply to an old post but I wanted to say thank you so much that worked.

Card reader is on site and everyone is happy.

Thank you for your help.
