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

6
  • Be sure to keep WACK updated, this has changed with every SDK release. If you want a clean report then use FlsAlloc instead like the UCRT does. Aug 6, 2016 at 5: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 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? Aug 6, 2016 at 5: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. Aug 6, 2016 at 5: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? Aug 9, 2016 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: stackoverflow.com/questions/38856582/…. Any suggestions will be highly appreciated. Aug 9, 2016 at 17:06

2 Answers 2

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

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);
}
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.