术语 | closehandle |
释义 | CloseHandle 语法: C++ BOOL WINAPI CloseHandle( __in HANDLE hObject ); CloseHandle函数 关闭一个打开的对象句柄。 参数 hObject [in] 一个有效的处理,以一个开放的对象。 返回值 如果函数成功,返回值为非零。 如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。 如果应用程序在调试器下运行,该函数将抛出一个异常,如果收到任何一个句柄值无效或者伪句柄值。发生这种情况,如果您关闭处理两倍,或者如果您处理上调用由FindFirstFile函数返回的,而不是调用FindClose函数CloseHandle。 备注 CloseHandle函数关闭句柄以下对象: 访问令牌 通信设备 控制台输入 控制台屏幕缓冲区 事件 文件 测绘档案 I / O完成端口 工作 邮槽 内存资源通知 互斥 命名管道 管 工艺 信号量 线 交易 可等待定时器 为函数创建这些对象文件表明,CloseHandle时,应当使用您完成的对象,会发生什么未完成的操作对象上处理后关闭。一般来说,CloseHandle无效指定的对象句柄,递减对象的句柄计数,并执行对象保留检查。在最后一个对象的句柄关闭,该对象是从系统中删除。如需对这些对象的创建者功能摘要,见内核对象。 一般来说,一个应用程序应调用CloseHandle每一次处理它打开。它通常没有必要调用CloseHandle如果一个函数,它使用一个处理失败,出现ERROR_INVALID_HANDLE,因为这种错误通常表明,处理已经失效。但是,某些功能的使用出现ERROR_INVALID_HANDLE表明对象本身不再有效。例如,一个函数,尝试使用手柄上的一个网络文件可能会失败,出现ERROR_INVALID_HANDLE如果网络连接中断,因为该文件对象不再可用。在这种情况下,应用程序应该关闭处理。 如果一个句柄交易,所有句柄绑定到交易之前应提交事务关闭。如果是交易处理与FILE_FLAG_DELETE_ON_CLOSE旗CreateFileTransacted要求打开,文件不会被删除,直到应用程序关闭的处理,并呼吁CommitTransaction。如需有关交易对象的信息,看到交易工作。 关闭一个线程句柄不会终止或删除相关的线程的线程对象。关闭一个进程句柄不关联的进程终止或删除的进程对象。要删除一个线程对象,必须终止线程,然后关闭所有的线程句柄。有关更多信息,请参阅终止线程。要删除一个进程对象,必须终止该进程,然后关闭所有句柄的进程。有关更多信息,请参阅终止一个进程。 关闭的句柄文件映射才能取得成功,即使有文件的意见,仍然是开放的。有关详细信息,请关闭文件映射对象。 不要使用CloseHandle函数关闭套接字。相反,使用关闭套接字函数,它释放这些组织包括:套接字句柄对象套接字关联的所有资源。有关更多信息,请参阅插座闭幕。 实例 有关示例,请参阅以快照和浏览过程。 要求: 最低支持:client-Windows 2000专业版 最低支持server-Windows 2000服务器 HeaderWinbase.h(头文件:winuser.h) LibraryKernel32.lib DLLKernel32.dll 参见 CreateFile CreateFileTransacted 的DeleteFile FindClose FindFirstFile 处理和对象函数 内核对象 对象接口 如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com) 生成日期:2009年8月27日 ==英文原文==CloseHandle Function Closes an open object handle. Syntax C++ BOOL WINAPI CloseHandle( __in HANDLE hObject ); Parameters hObject [in] A valid handle to an open object. Return Value If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError . If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call CloseHandle on a handle returned by the FindFirstFile function instead of calling the FindClose function. Remarks The CloseHandle function closes handles to the following objects: Access token Communications device Console input Console screen buffer Event File File mapping I/O completion port Job Mailslot Memory resource notification Mutex Named pipe Pipe Process Semaphore Thread Transaction Waitable timer The documentation for the functions that create these objects indicates that CloseHandle should be used when you are finished with the object, and what happens to pending operations on the object after the handle is closed. In general, CloseHandle 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. For a summary of the creator functions for these objects, see Kernel Objects . Generally, an application should call CloseHandle once for each handle it opens. It is usually not necessary to call CloseHandle if a function that uses a handle fails with ERROR_INVALID_HANDLE, because this error usually indicates that the handle is already invalidated. However, some functions use ERROR_INVALID_HANDLE to indicate that the object itself is no longer valid. For example, a function that attempts to use a handle to a file on a network might fail with ERROR_INVALID_HANDLE if the network connection is severed, because the file object is no longer available. In this case, the application should close the handle. If a handle is transacted, all handles bound to a transaction should be closed before the transaction is committed. If a transacted handle was opened by calling CreateFileTransacted with the FILE_FLAG_DELETE_ON_CLOSE flag, the file is not deleted until the application closes the handle and calls CommitTransaction . For more information about transacted objects, see Working With Transactions . Closing a thread handle does not terminate the associated thread or remove the thread object. Closing a process handle does not terminate the associated process or remove the process object. To remove a thread object, you must terminate the thread, then close all handles to the thread. For more information, see Terminating a Thread . To remove a process object, you must terminate the process, then close all handles to the process. For more information, see Terminating a Process . Closing a handle to a file mapping can succeed even when there are file views that are still open. For more information, see Closing a File Mapping Object . Do not use the CloseHandle function to close a socket. Instead, use the closesocket function, which releases all resources associated with the socket including the handle to the socket object. For more information, see Socket Closure . Examples For an example, see Taking a Snapshot and Viewing Processes . Requirements Minimum supported clientWindows 2000 Professional Minimum supported serverWindows 2000 Server HeaderWinbase.h (include Windows.h) LibraryKernel32.lib DLLKernel32.dll See Also CreateFile CreateFileTransacted DeleteFile FindClose FindFirstFile Handle and Object Functions Kernel Objects Object Interface Send comments about this topic to Microsoft Build date: 8/27/2009 ==原始网址==http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx\n |
随便看 |
|
windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。