Created
May 18, 2013 06:33
-
-
Save wyyqyl/5603483 to your computer and use it in GitHub Desktop.
A code snippet shows how to use Tls callback in VC++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
VOID NTAPI MyCallback(PVOID handle, DWORD reason, PVOID resv); | |
#pragma data_seg(".CRT$XLB") | |
PIMAGE_TLS_CALLBACK tls_entry = MyCallback; | |
#pragma data_seg() | |
#pragma comment(linker, "/INCLUDE:__tls_used") | |
#pragma comment(linker, "/INCLUDE:_tls_entry") | |
VOID NTAPI MyCallback(PVOID handle, DWORD reason, PVOID resv) | |
{ | |
if (reason == DLL_PROCESS_ATTACH) { | |
printf("DLL_PROCESS_ATTACH\n"); | |
} else if (reason == DLL_PROCESS_DETACH) { | |
printf("DLL_PROCESS_DETACH\n"); | |
} | |
} | |
int main() { | |
printf("main\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment