Proper way close WinAPI HANDLEs (avoiding of repeated closing)
问题 I have some handle and I need to close it. There is some places in code, where handle may be closed. So, is this a right way to close handle? HANDLE h; .... if ( h != INVALID_HANDLE_VALUE ) { ::CloseHandle(h); h = INVALID_HANDLE_VALUE; } There is a same question about bitmap handles: HBITMAP hb; .... if ( hb != INVALID_HANDLE_VALUE ) { ::DeleteObject(hb); hb = INVALID_HANDLE_VALUE; } EDIT: I think, there is some misunderstanding. I know CloseHandle is for closing handles. I'd like to know