为什么 GetExitCodeThread() 函数获得的是线程句柄?

网上查阅GetExitCodeThread() 函数的作用是这个函数是获得线程的退出码,为何退出码恰好等于函数句柄?

相关代码如下:

// 请把代码文本粘贴到下方(请勿用图片代替代码)
【函数1:】
DWORD getMyBaseAddressGMH()
{

return (DWORD)GetModuleHandle(NULL);

}
【函数2:】
DWORD getRemoteBaseAddress(HANDLE process)
{

DWORD newBase;
// get the address of kernel32.dll
HMODULE k32 = GetModuleHandleA("kernel32.dll");
// get the address of GetModuleHandle()
LPVOID funcAdr = GetProcAddress(k32, "GetModuleHandleA");
if (!funcAdr) funcAdr = GetProcAddress(k32, "GetModuleHandleW");
// create the thread
HANDLE thread = CreateRemoteThread(process, NULL, NULL, (LPTHREAD_START_ROUTINE)funcAdr, NULL, NULL, NULL);
// let the thread finish
WaitForSingleObject(thread, INFINITE);

// get the exit code
GetExitCodeThread(thread, &newBase);
printf("ExitCode is : %d\n", newBase);
// clean up the thread handle
CloseHandle(thread);
return newBase;

}

其中函数1的 return值 和函数2 的newBase值都一样,但函数1的return值是获取的当前程序句柄,而函数2的newBase值是线程的退出码,二者为何会相同?(如图)

图片描述

阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题