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;
}
一个线程打开一个文件后,
关闭句柄,然后启动另一个线程,打开这个文件,得到的句柄跟第一次打开是一样的,为什么?
[注意]APP应用上架合规检测服务,协助应用顺利上架!