0

I have a C# app targeting Windows-10 Desktop & Mobile platforms. My app calls in to Windows Runtime Component written in C++ with c++/cx bindings.
My C++ code uses Thread Local Storage api's like TlsAlloc, TlsGetValue, TlsSetValue and TlsFree. When I run Windows App Certification Kit Tests (WACK tests), it complains about unavailability of these api, in the store app's.

◦API TlsAlloc in kernel32.dll is not supported for this application type. sample.dll calls this API.
◦API TlsFree in kernel32.dll is not supported for this application type. sample.dll calls this API.
◦API TlsGetValue in kernel32.dll is not supported for this application type. sample.dll calls this API.
◦API TlsSetValue in kernel32.dll is not supported for this application type. sample.dll calls this API.

I couldnt see alternatives for these api's for Windows-10 store app's. This MSDN page only talks about these api's availability on Windows Phone 8. I couldnt find any specific info regarding these api's for Windows-10

I am compiling my native C++ libs using -DWINAPI_FAMILY=WINAPI_FAMILY_APP flag

Any suggestions will be highly appreciated

Ganesh kudva
  • 990
  • 3
  • 13
  • 34
  • Be sure to keep WACK updated, this has changed with every SDK release. If you want a clean report then [use FlsAlloc instead](http://stackoverflow.com/a/27979758/17034) like the UCRT does. – Hans Passant Aug 06 '16 at 05:03
  • Hi @HansPassant, Thanks for the response. When you suggest to use FlsAlloc, does that mean, in my code, I need to change all calls to TlsAlloc into FlsAlloc or is there a macro setting which can do this trick for me. The [MSDN page](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686801(v=vs.85).aspx) says that "**When a Windows Phone Store app calls this function it is replaced with an inline call to FlsAlloc**". Does this replacement trickery happen with Windows-10? or is this only limited to WinPhone-8? – Ganesh kudva Aug 06 '16 at 05:21
  • SDK v10 allows TlsAlloc() to be used by any UWP app. Which is why you need to make sure that you have an up-to-date WACK. – Hans Passant Aug 06 '16 at 05:24
  • Hi @HansPassant, Thanks for the response, I update my WACK tool. I now have version: **10.0.14393.33**. After the update though, when I select **Validate Store App** option from the WACK tool, it doesnt seem to find the app installed on my machine. My app is installed on the machine & I can see it in **Start Menu -> All apps**. WACK tool was able to find my app installed on the machine prior to this update. Has anything changes in the WACK tool in this update? – Ganesh kudva Aug 09 '16 at 17:05
  • Hi @HansPassant, Since **Validate Store App** option was not working out, I tried to create an app package, but I am hitting this error: http://stackoverflow.com/questions/38856582/uwp-unable-to-register-app-for-windows-store-release. Any suggestions will be highly appreciated. – Ganesh kudva Aug 09 '16 at 17:06
  • Off topic, but is there any reason to use this over `thread_local`? – RamblingMad Aug 18 '16 at 04:18

2 Answers2

0

@HansPassant answer helped to figure this out.

Thread Local Storage(TLS) api's are supported in UWP Windows-10 Store apps.
I had to upgrade to Windows SDK version 10.0.14393.33
Any version prior to this will error out on TLS api's

Ganesh kudva
  • 990
  • 3
  • 13
  • 34
0

For Windows 10 Phone UWP apps, the documentation appears to be wrong. You can use the Tls* functions if you link to kernel32.lib, but when you try to deploy it, it fails with a missing DLL error.

Instead, if you are linking to existing code that uses TLS, you can use the following emulation (put it anywhere in your code):

extern "C" {
DWORD WINAPI __imp_TlsAlloc() {
    return FlsAlloc(nullptr);
}
BOOL WINAPI __imp_TlsFree(DWORD index) {
    return FlsFree(index);
}
BOOL WINAPI __imp_TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) {
    return FlsSetValue(dwTlsIndex, lpTlsValue);
}
LPVOID WINAPI __imp_TlsGetValue(DWORD dwTlsIndex) {
    return FlsGetValue(dwTlsIndex);
}
}