News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DeleteObject OR CloseHandle ?

Started by G`HOST, November 19, 2005, 07:30:47 PM

Previous topic - Next topic

G`HOST

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

arafel

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.

Tedd

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
No snowflake in an avalanche feels responsible.