Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TLS callback example in C++

Featured Replies

Posted

I have following code:

#include <Windows.h>
#include <cstdio>


__declspec(thread) int a;
void NTAPI on_tls_callback(PVOID h, DWORD dwReason, PVOID pv)
{
    a = 43;
    MessageBox(nullptr, L"aaaa", L"bbb", MB_OK);
}

#pragma data_seg(".CRT$XLB")
PIMAGE_TLS_CALLBACK p_thread_callback = on_tls_callback;
#pragma data_seg()

int main()
{
    printf("%d\n", a);

    getchar();
}

I want to execute on_tls_callback() before main, but it does not work on MSVC 2015.

Can you explain how can I use TLS callback?

Edited by Aldhard Oswine

  • Author

This works:
 

#include <Windows.h>
#include <cstdio>
__declspec(thread) int a;
void NTAPI on_tls_callback(void* dll, DWORD reason, void* reserved)
{
	a = 543;
	MessageBox(nullptr, L"aaaa", L"bbb", MB_OK);
}

#pragma comment (linker, "/INCLUDE:__tls_used")
#pragma comment (linker, "/INCLUDE:__xl_b")
#pragma data_seg(".CRT$XLB")
EXTERN_C

PIMAGE_TLS_CALLBACK _xl_b = on_tls_callback;
#pragma data_seg()

int main()
{
	printf("%d\n", a);

	getchar();
}

 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.