ServerAgent.CloseHandle(IntPtr) Method

Definition

The CloseHandle method closes an open Microsoft Windows object handle.

public:
 static int CloseHandle(IntPtr hObject);
public static int CloseHandle (IntPtr hObject);
Public Shared Function CloseHandle (hObject As IntPtr) As Integer

Parameters

hObject
IntPtr

The object handle to close, such as the handle to any security token.

Returns

Remarks

If the function succeeds, the return value is nonzero. Otherwise, it returns zero (0). To get the specific Windows error code, create a new instance of Win32Exception, which will obtain the corresponding Windows error code, as demonstrated in the following code example.

if (ServerAgent.CloseHandle(mySecurityToken) == 0) {
 Win32Exception e = new Win32Exception();
 Console.WriteLine("Windows Error {0}: {1}", e.ErrorCode, e.Message);
}

In the Microsoft Windows Platform SDK, a list of Windows error codes appears in Winerror.h.

Calling this method is identical to calling the Windows CloseHandle function in kernel32.lib (defined in Windows.h).

Applies to