-
-
[求助][求助][求助]TLS回调函数运行结果不正确,请大神帮忙
-
发表于: 2015-7-8 17:30 2502
-
以下是我写的一个TLS回调函数,运行结果与不正确,不知道原因,看看有没有大神能帮忙。
#include <windows.h>
#include <stdio.h>
#pragma comment(linker,"/INCLUDE:__tls_used")
void NTAPI MY_TLS_CALLBACK(PVOID DllHandle,DWORD Reason,PVOID Reserved)
{
printf("HELLO WORLD!");
}
#pragma data_seg(".CRT$XLX")
PIMAGE_TLS_CALLBACK pTLS_CALLBACKs=MY_TLS_CALLBACK;
#pragma data_seg()
DWORD WINAPI ThreadProc(LPVOID lParam)
{
printf("ThreadProc() start\n");
printf("ThreadProc() end\n");
return 0;
}
int main()
{
HANDLE hThread=NULL;
printf("main() start\n");
hThread=CreateThread(NULL,0,ThreadProc,NULL,0,NULL);
WaitForSingleObject(hThread,60*1000);
CloseHandle(hThread);
printf("main() end\n");
system("PAUSE");
return 0;
}
运行结果如下所示:
main() start
ThreadProc() start
ThreadProc() end
main() end
也就是回调函数没有在创建/终止线程的时候自动调用执行。这是怎么一回事呢?求帮忙啊,小弟在此谢过。
#include <windows.h>
#include <stdio.h>
#pragma comment(linker,"/INCLUDE:__tls_used")
void NTAPI MY_TLS_CALLBACK(PVOID DllHandle,DWORD Reason,PVOID Reserved)
{
printf("HELLO WORLD!");
}
#pragma data_seg(".CRT$XLX")
PIMAGE_TLS_CALLBACK pTLS_CALLBACKs=MY_TLS_CALLBACK;
#pragma data_seg()
DWORD WINAPI ThreadProc(LPVOID lParam)
{
printf("ThreadProc() start\n");
printf("ThreadProc() end\n");
return 0;
}
int main()
{
HANDLE hThread=NULL;
printf("main() start\n");
hThread=CreateThread(NULL,0,ThreadProc,NULL,0,NULL);
WaitForSingleObject(hThread,60*1000);
CloseHandle(hThread);
printf("main() end\n");
system("PAUSE");
return 0;
}
运行结果如下所示:
main() start
ThreadProc() start
ThreadProc() end
main() end
也就是回调函数没有在创建/终止线程的时候自动调用执行。这是怎么一回事呢?求帮忙啊,小弟在此谢过。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
看原图
赞赏
雪币:
留言: