HANDLE hFile = CreateFileW(L"C:\\Users\\xxx\\Desktop\\000.docx", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
DisplayInfoExW(__FUNCTIONW__, DBG_LVL_INFO, L"handle = %d", hFile);
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
HANDLE hThread = NULL;
hThread = (HANDLE)_beginthreadex(NULL,
0,
(unsigned int(__stdcall*)(void*))TestThread,
NULL,
0,
NULL);
CloseHandle(hThread);
hThread = NULL;
for (;;)
{
Sleep(1000);
}
unsigned int __stdcall TestThread(void* lpParam)
{
HANDLE hFile = CreateFileW(L"C:\\Users\\xxx\\Desktop\\000.docx", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hFile)
{
DisplayInfoExW(__FUNCTIONW__, DBG_LVL_INFO, L"handle = %d", hFile);
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
return 0;
}
一个线程打开一个文件后,
关闭句柄,然后启动另一个线程,打开这个文件,得到的句柄跟第一次打开是一样的,为什么?
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课