Zamiana pseudo HANDLE w prawdziwy

środa, 25 kwietnia 2007 02:00
Drukuj
Ocena użytkowników: / 2
SłabyŚwietny 

 
HANDLE __fastcall uchwyt()
{
// GetCurrentThread() zwraca a "pseudo" handle
// "pseudo" handle może byc używany tylko przez wątek do którego należy
// Zamiana pseudo handle w prawdziwy handle
HANDLE hThreadPseudo;
HANDLE hThread;
hThreadPseudo = GetCurrentThread();
DuplicateHandle(
    GetCurrentProcess(), // hSourceProcessHandle
    hThreadPseudo,         // the pseudo handle of this thread that we want
                             // to convert to a real thread Handle
    GetCurrentProcess(), // hTargetProcessHandle
    &hThread,         // The real handle, created by this method call.
    0,             // Desired Access, irrelevant because we specify
                             // DUPLICATE_SAME_ACCESS, as last parameter
    FALSE,             // Created real handle will not be inheritable
    DUPLICATE_SAME_ACCESS
         );
return hThread;
}