CloseHandle
Windows Mobile SupportedWindows Embedded CE Supported
8/28/2008

This function closes an open object handle. A remote API (RAPI) version of this function exists called CeCloseHandle (RAPI).

Syntax


BOOL CloseHandle(
  HANDLE hObject
);
Parameters

hObject

[in] Handle to an open object.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

For All Platforms:

This function closes handles to the following objects:

  • Communications device
  • Database
  • Database enumeration context
  • Event
  • File
  • File-mapping object
  • Mutex
  • Process
  • Socket
  • Thread

This function invalidates the specified object handle, decrements the object's handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system. Persistent objects, such as databases and files, remain in storage, but must be re-opened to be accessed again.

Closing a thread handle does not terminate the associated thread. To remove a thread object, you must terminate the thread, and then close all handles to the thread.

Use this function to close handles returned by calls to the CreateFile function. Use the FindClose function to close handles returned by calls to the FindFirstFile function.

When an application running in user mode calls this function, the kernel calls internal functions that clean up any associated resources, such as MyFileSystem_PreCloseHandle and MyFileSystem_CloseHandle.

For Windows Embedded CE:

In the past, when a user-mode call closed a handle, a failure of the internal preclose and close functions would cause this function to fail. This behavior has changed. With Windows Embedded CE 6.0 and later, this function succeeds on any valid handle, regardless of results that might be returned by the internal preclose and close functions.

Requirements

Headerwinbase.h
Librarycoredll.lib
Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later
See Also

Reference

File I/O Functions
CreateFile
CreateFileForMapping
CreateFileMapping
CeFindFirstDatabaseEx (CEDB)
DeleteFile
FindClose
FindFirstFile

Tags : closehandle


Page view tracker