Consultor Eletrônico



Kbase 17321: How to Call WIN32 API Function: CloseHandle
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
How to Call WIN32 API Function: CloseHandle

DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.

INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called CloseHandle. This function invalidates the object handle,
decrements the object's handle count, and performs object retention
checks. Once the last handle of an object is closed, the object is
removed from the system. An application can use this function to
close the following types of object handles:

- Console input or output
- Event file
- File mapping
- Mutex
- Named pipe
- Process
- Semaphore
- Thread

This code has been tested on Windows NT 4.0 Workstation only.


DEFINE VARIABLE intObjectHandle AS INTEGER NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

PROCEDURE CloseHandle EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER intObjectHandle AS LONG.
DEFINE RETURN PARAMETER intResult AS LONG.
END PROCEDURE.

RUN CloseHandle (INPUT intObjectHandle, OUTPUT intResult).

IF intResult = 1 THEN
MESSAGE "File Handle Closed" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "File Handle *NOT* Closed" VIEW-AS ALERT-BOX.

Progress Software Technical Support Note # 17321