-
-
[求助]不同线程打开同一个文件的句柄是一样的?
-
发表于:
2016-5-3 19:18
5291
-
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;
}
一个线程打开一个文件后,
关闭句柄,然后启动另一个线程,打开这个文件,得到的句柄跟第一次打开是一样的,为什么?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!