System.Runtime.InteropServices.HandleRef Structure

Assembly: Mscorlib.dll
Namespace: System.Runtime.InteropServices
Summary
Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke.
C# Syntax:
public struct HandleRef
Remarks
If the managed object is not referenced anywhere after the platform invoke call, it is possible that the garbage collector will finalize the managed object. This releases the resource and invalidates the handle, causing the platform invoke call to fail. Wrapping your handle with HandleRef guarantees that the managed object will not be garbage collected until the platform invoke call is finished.
See also:
System.Runtime.InteropServices Namespace

System.Runtime.InteropServices.HandleRef Member List:

Public Constructors
ctor #1 Initializes a new instance of the HandleRef class with the object to wrap and a handle to the resource used by unmanaged code.
Public Properties
Handle Read-only

Gets the handle to a resource.
Wrapper Read-only

Gets the object holding the handle to a resource.
Public Methods
Equals
(inherited from System.ValueType)
See base class member description: System.ValueType.Equals


Indicates whether this instance and a specified object are equal.
GetHashCode
(inherited from System.ValueType)
See base class member description: System.ValueType.GetHashCode


Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.ValueType)
See base class member description: System.ValueType.ToString


Returns the fully qualified type name of this instance.
Public Operators and Type Conversions
op_Explicit
(convert System.Runtime.InteropServices.HandleRef to System.IntPtr)
Returns the handle to a resource of the specified HandleRef object.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Runtime.InteropServices.HandleRef Member Details

ctor #1
Summary
Initializes a new instance of the HandleRef class with the object to wrap and a handle to the resource used by unmanaged code.
C# Syntax:
public HandleRef(
   object wrapper,
   IntPtr handle
);
Parameters:

wrapper

Managed object that should not be finalized until the platform invoke call returns.

handle

Handle to a resource.

Return to top


Property: Handle (read-only)
Summary
Gets the handle to a resource.
C# Syntax:
public IntPtr Handle {get;}

Return to top


Property: Wrapper (read-only)
Summary
Gets the object holding the handle to a resource.
C# Syntax:
public object Wrapper {get;}

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.ValueType.Equals

Summary
Indicates whether this instance and a specified object are equal.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

Another object to compare to.

Return Value:
true if obj and this instance are the same type and represent the same value; otherwise, false.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~HandleRef();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.ValueType.GetHashCode

Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer that is the hash code for this instance.
Remarks
The ValueType.GetHashCode method applies to types derived from ValueType. One or more fields of the derived type is used to calculate the return value. If one or more of those fields contains a mutable value, the return value might be unpredictable, and unsuitable for use as a key in a hash table.

For more information, see Object.GetHashCode, and Hashtable.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: op_Explicit System.IntPtr(
   HandleRef value
)
Summary
Returns the handle to a resource of the specified HandleRef object.
C# Syntax:
public static operator explicit IntPtr(
   HandleRef value
);
Parameters:

value

The object that needs a handle.

Return Value:
The handle to a resource of the specified HandleRef object.

Return to top


Method: ToString()
Inherited
See base class member description: System.ValueType.ToString

Summary
Returns the fully qualified type name of this instance.
C# Syntax:
public override string ToString();
Return Value:
A String containing a fully qualified type name.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.