The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: G`HOST on November 19, 2005, 07:30:47 PM

Title: DeleteObject OR CloseHandle ?
Post by: G`HOST on November 19, 2005, 07:30:47 PM
From win32 API

QuoteThe DeleteObject function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. After the object is deleted, the specified handle is no longer valid.

QuoteThe CloseHandle function closes an open object handle.

What function should i use to close the handle returned by GetModuleHandle call and GetCommandLine call.(Or i dont need to close it.)
I think i should be using CloseHandle,But this is not working and i m getting "The handle is invalid." error.
But DeletObject is working fine here.
One more thing should i be closing the Ids something like
"invoke CreateThread,NULL,NULL,eax,0,0,ADDR ThreadId"
.....ThreadId
Title: Re: DeleteObject OR CloseHandle ?
Post by: arafel on November 19, 2005, 07:58:11 PM
GetModuleHandle retrieves already existing handle so there is no need to do any *freeing* on it.
GetCommandLine retrieves pointer to the command line string that is already exist when you execute the app. no need to free it either.
As for the CreateThread, you can close the handle returned in EAX if you don't need it. This wont destroy the thread, but you wont be able to use functions that use thread handle like ThreadTerminate for example.
Title: Re: DeleteObject OR CloseHandle ?
Post by: Tedd on November 21, 2005, 11:22:46 AM
DeleteObject is for GDI objects only (pens, brushes, fonts, bitmaps, etc)
CloseHandle is for files, console handles, pipes, threads, and processes..

But for processes and threads, that means 'extra' processes/threads create by your process, not your process itself.
ExitProcess/ExitThread are used for this :wink