2013年10月10日星期四

About CloseHandle () a problem

CreateProcess (NULL, szFileName, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, & si, & pi); creates a process kernel object later

CloseHandle (pi.hThread);
CloseHandle (pi.hProcess);
can count by 1 , then if I use

HANDLE g_hProcess = pi.hProcess;
CloseHandle (pi.hThread);
CloseHandle (g_hProcess);
CloseHandle (pi.hProcess);
instead of the above code, then is not it will count minus 2 ? Or that the use HANDLE g_hProcess = pi.hProcess; they also make the kernel count plus one ? Second code is equivalent to the first paragraph ?
------ Solution ---------------------------------------- ----
in Windows handle is process-related data , handle different processes may point to the same core structure , they differ in the value of the process may also be the same .
In a process calls CloseHandle after that HANDLE is already illegal , and if there will be an exception and then call generated . Tips illegal handle.
------ For reference only -------------------------------------- -

没有评论:

发表评论