CriticalHandleZeroOrMinusOneIsInvalidとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > CriticalHandleZeroOrMinusOneIsInvalidの意味・解説 

CriticalHandleZeroOrMinusOneIsInvalid クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

値 0 または -1 が無効なハンドルである Win32 クリティカル ハンドル実装基本クラス提供します

名前空間: Microsoft.Win32.SafeHandles
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public MustInherit Class
 CriticalHandleZeroOrMinusOneIsInvalid
    Inherits CriticalHandle
Dim instance As CriticalHandleZeroOrMinusOneIsInvalid
public abstract class CriticalHandleZeroOrMinusOneIsInvalid
 : CriticalHandle
public ref class CriticalHandleZeroOrMinusOneIsInvalid
 abstract : public CriticalHandle
public abstract class CriticalHandleZeroOrMinusOneIsInvalid
 extends CriticalHandle
public abstract class CriticalHandleZeroOrMinusOneIsInvalid
 extends CriticalHandle
解説解説

このクラスは System.Runtime.InteropServices.CriticalHandle クラスから派生したクラスです。このクラス無効なハンドル形式記述します。たとえば、無効なハンドル値として -1 を使用するハンドルもあれば、0 を使用するハンドルあります。このクラスからさらにファイル ハンドルレジストリ ハンドルなどへ派生してさらなる特化が可能です。

既存マネージ ラッパー持たないアンマネージ リソースラップする必要があるときは、CriticalHandleZeroOrMinusOneIsInvalid クラス使用します

メモメモ

クリティカル ハンドルセキュリティおよびスレッド セーフに関する重要な情報については、CriticalHandle クラストピック参照してください

使用例使用例

CriticalHandleZeroOrMinusOneIsInvalid クラスから派生したクラス作成する方法コード例次に示します。この例では、アンマネージ メモリへのポインタラップするクラス作成します

Imports System
Imports System.Security.Permissions
Imports System.Runtime.InteropServices
Imports Microsoft.Win32.SafeHandles



Class Example

    Public Shared Sub Main()

        Dim ptr As IntPtr = Marshal.AllocHGlobal(10)

        Console.WriteLine("Ten bytes of unmanaged memory allocated.")

        Dim memHabdle As New
 CriticalUnmanagedMemoryHandle(ptr)

        If memHabdle.IsInvalid Then
            Console.WriteLine("CriticalUnmanagedMemoryHandle is
 invalid!.")
        Else
            Console.WriteLine("CriticalUnmanagedMemoryHandle class
 initialized to unmanaged memory.")
        End If

        Console.ReadLine()

    End Sub
End Class




' Demand unmanaged code permission to use this class.
<SecurityPermission(SecurityAction.Demand, UnmanagedCode:=True)> _
NotInheritable Class CriticalUnmanagedMemoryHandle
    Inherits CriticalHandleZeroOrMinusOneIsInvalid


    ' Set the handle.
    Friend Sub New(ByVal
 preexistingHandle As IntPtr)
        SetHandle(preexistingHandle)

    End Sub


    ' Perform any specific actions to release the 
    ' handle in the ReleaseHandle method.
    ' Often, you need to use Pinvoke to make
    ' a call into the Win32 API to release the 
    ' handle. In this case, however, we can use
    ' the Marshal class to release the unmanaged
    ' memory.
    Protected Overrides Function
 ReleaseHandle() As Boolean
        ' "handle" is the internal
        ' value for the IntPtr handle.
        ' If the handle was set,
        ' free it. Return success.
        If handle <> IntPtr.Zero Then

            ' Free the handle.
            Marshal.FreeHGlobal(handle)

            ' Set the handle to zero.
            handle = IntPtr.Zero

            ' Return success.
            Return True
        End If

        ' Return false. 
        Return False

    End Function
End Class

using System;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

namespace CriticalHandleExamples
{
    class Example
    {
        public static void
 Main()
        {

            IntPtr ptr = Marshal.AllocHGlobal(10);

            Console.WriteLine("Ten bytes of unmanaged memory allocated.");

            CriticalUnmanagedMemoryHandle memHabdle = new CriticalUnmanagedMemoryHandle(ptr);

            if (memHabdle.IsInvalid)
            {
                Console.WriteLine("CriticalUnmanagedMemoryHandle is invalid!.");
            }
            else
            {
                Console.WriteLine("CriticalUnmanagedMemoryHandle class
 initialized to unmanaged memory.");
            }

            Console.ReadLine();
        }
    }




    // Demand unmanaged code permission to use this class.
    [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
    sealed class CriticalUnmanagedMemoryHandle : CriticalHandleZeroOrMinusOneIsInvalid
    {

        // Set the handle.
        internal CriticalUnmanagedMemoryHandle(IntPtr preexistingHandle)
        {
            SetHandle(preexistingHandle);
        }

        // Perform any specific actions to release the 
        // handle in the ReleaseHandle method.
        // Often, you need to use Pinvoke to make
        // a call into the Win32 API to release the 
        // handle. In this case, however, we can use
        // the Marshal class to release the unmanaged
        // memory.
        override protected bool ReleaseHandle()
        {
            // "handle" is the internal
            // value for the IntPtr handle.

            // If the handle was set,
            // free it. Return success.
            if (handle != IntPtr.Zero)
            {

                // Free the handle.
                Marshal.FreeHGlobal(handle);

                // Set the handle to zero.
                handle = IntPtr.Zero;

                // Return success.
                return true;

            }

            // Return false. 
            return false;

        }
    }
}

継承階層継承階層
System.Object
   System.Runtime.ConstrainedExecution.CriticalFinalizerObject
     System.Runtime.InteropServices.CriticalHandle
      Microsoft.Win32.SafeHandles.CriticalHandleZeroOrMinusOneIsInvalid
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CriticalHandleZeroOrMinusOneIsInvalid メンバ
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle

CriticalHandleZeroOrMinusOneIsInvalid コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

CriticalHandleZeroOrMinusOneIsInvalid クラス新しインスタンス初期化します。

名前空間: Microsoft.Win32.SafeHandles
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As New CriticalHandleZeroOrMinusOneIsInvalid
protected CriticalHandleZeroOrMinusOneIsInvalid ()
protected:
CriticalHandleZeroOrMinusOneIsInvalid ()
protected CriticalHandleZeroOrMinusOneIsInvalid ()
protected function CriticalHandleZeroOrMinusOneIsInvalid
 ()
使用例使用例

CriticalHandleZeroOrMinusOneIsInvalid クラスから派生したクラス作成する方法コード例次に示します。この例では、アンマネージ メモリへのポインタラップするクラス作成します

Imports System
Imports System.Security.Permissions
Imports System.Runtime.InteropServices
Imports Microsoft.Win32.SafeHandles



Class Example

    Public Shared Sub Main()

        Dim ptr As IntPtr = Marshal.AllocHGlobal(10)

        Console.WriteLine("Ten bytes of unmanaged memory allocated.")

        Dim memHabdle As New
 CriticalUnmanagedMemoryHandle(ptr)

        If memHabdle.IsInvalid Then
            Console.WriteLine("CriticalUnmanagedMemoryHandle is
 invalid!.")
        Else
            Console.WriteLine("CriticalUnmanagedMemoryHandle class
 initialized to unmanaged memory.")
        End If

        Console.ReadLine()

    End Sub
End Class




' Demand unmanaged code permission to use this class.
<SecurityPermission(SecurityAction.Demand, UnmanagedCode:=True)> _
NotInheritable Class CriticalUnmanagedMemoryHandle
    Inherits CriticalHandleZeroOrMinusOneIsInvalid


    ' Set the handle.
    Friend Sub New(ByVal
 preexistingHandle As IntPtr)
        SetHandle(preexistingHandle)

    End Sub


    ' Perform any specific actions to release the 
    ' handle in the ReleaseHandle method.
    ' Often, you need to use Pinvoke to make
    ' a call into the Win32 API to release the 
    ' handle. In this case, however, we can use
    ' the Marshal class to release the unmanaged
    ' memory.
    Protected Overrides Function
 ReleaseHandle() As Boolean
        ' "handle" is the internal
        ' value for the IntPtr handle.
        ' If the handle was set,
        ' free it. Return success.
        If handle <> IntPtr.Zero Then

            ' Free the handle.
            Marshal.FreeHGlobal(handle)

            ' Set the handle to zero.
            handle = IntPtr.Zero

            ' Return success.
            Return True
        End If

        ' Return false. 
        Return False

    End Function
End Class

using System;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

namespace CriticalHandleExamples
{
    class Example
    {
        public static void
 Main()
        {

            IntPtr ptr = Marshal.AllocHGlobal(10);

            Console.WriteLine("Ten bytes of unmanaged memory allocated.");

            CriticalUnmanagedMemoryHandle memHabdle = new CriticalUnmanagedMemoryHandle(ptr);

            if (memHabdle.IsInvalid)
            {
                Console.WriteLine("CriticalUnmanagedMemoryHandle is invalid!.");
            }
            else
            {
                Console.WriteLine("CriticalUnmanagedMemoryHandle class
 initialized to unmanaged memory.");
            }

            Console.ReadLine();
        }
    }




    // Demand unmanaged code permission to use this class.
    [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
    sealed class CriticalUnmanagedMemoryHandle : CriticalHandleZeroOrMinusOneIsInvalid
    {

        // Set the handle.
        internal CriticalUnmanagedMemoryHandle(IntPtr preexistingHandle)
        {
            SetHandle(preexistingHandle);
        }

        // Perform any specific actions to release the 
        // handle in the ReleaseHandle method.
        // Often, you need to use Pinvoke to make
        // a call into the Win32 API to release the 
        // handle. In this case, however, we can use
        // the Marshal class to release the unmanaged
        // memory.
        override protected bool ReleaseHandle()
        {
            // "handle" is the internal
            // value for the IntPtr handle.

            // If the handle was set,
            // free it. Return success.
            if (handle != IntPtr.Zero)
            {

                // Free the handle.
                Marshal.FreeHGlobal(handle);

                // Set the handle to zero.
                handle = IntPtr.Zero;

                // Return success.
                return true;

            }

            // Return false. 
            return false;

        }
    }
}

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CriticalHandleZeroOrMinusOneIsInvalid クラス
CriticalHandleZeroOrMinusOneIsInvalid メンバ
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle

CriticalHandleZeroOrMinusOneIsInvalid フィールド


プロテクト フィールドプロテクト フィールド

  名前 説明
プロテクト フィールド handle  ラップされるハンドル指定します。 ( CriticalHandle から継承されます。)
参照参照

関連項目

CriticalHandleZeroOrMinusOneIsInvalid クラス
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle

CriticalHandleZeroOrMinusOneIsInvalid プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ IsClosed  ハンドル閉じているかどうかを示す値を取得します。 ( CriticalHandle から継承されます。)
パブリック プロパティ IsInvalid オーバーライドされますハンドル無効かどうかを示す値を取得します
参照参照

関連項目

CriticalHandleZeroOrMinusOneIsInvalid クラス
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle

CriticalHandleZeroOrMinusOneIsInvalid メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CriticalHandleZeroOrMinusOneIsInvalid クラス
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle

CriticalHandleZeroOrMinusOneIsInvalid メンバ

値 0 または -1 が無効なハンドルである Win32 クリティカル ハンドル実装基本クラス提供します

CriticalHandleZeroOrMinusOneIsInvalid データ型公開されるメンバを以下の表に示します


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド CriticalHandleZeroOrMinusOneIsInvalid CriticalHandleZeroOrMinusOneIsInvalid クラス新しインスタンス初期化します。
プロテクト フィールドプロテクト フィールド
  名前 説明
プロテクト フィールド handle  ラップされるハンドル指定します。(CriticalHandle から継承されます。)
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CriticalHandleZeroOrMinusOneIsInvalid クラス
Microsoft.Win32.SafeHandles 名前空間
CriticalHandle



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CriticalHandleZeroOrMinusOneIsInvalid」の関連用語

CriticalHandleZeroOrMinusOneIsInvalidのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CriticalHandleZeroOrMinusOneIsInvalidのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS