IntPtr 構造体
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ビット幅がポインターと同じ符号付き整数を表します。
public value class IntPtr
public value class IntPtr : IComparable, IComparable<IntPtr>, IEquatable<IntPtr>, IFormattable, System::Runtime::Serialization::ISerializable
public value class IntPtr : IComparable, IComparable<IntPtr>, IEquatable<IntPtr>, ISpanFormattable, System::Runtime::Serialization::ISerializable
public value class IntPtr : IComparable<IntPtr>, IEquatable<IntPtr>, IParsable<IntPtr>, ISpanParsable<IntPtr>, System::Numerics::IAdditionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IAdditiveIdentity<IntPtr, IntPtr>, System::Numerics::IBinaryInteger<IntPtr>, System::Numerics::IBinaryNumber<IntPtr>, System::Numerics::IBitwiseOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IComparisonOperators<IntPtr, IntPtr, bool>, System::Numerics::IDecrementOperators<IntPtr>, System::Numerics::IDivisionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IEqualityOperators<IntPtr, IntPtr, bool>, System::Numerics::IIncrementOperators<IntPtr>, System::Numerics::IMinMaxValue<IntPtr>, System::Numerics::IModulusOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IMultiplicativeIdentity<IntPtr, IntPtr>, System::Numerics::IMultiplyOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::INumber<IntPtr>, System::Numerics::INumberBase<IntPtr>, System::Numerics::IShiftOperators<IntPtr, int, IntPtr>, System::Numerics::ISignedNumber<IntPtr>, System::Numerics::ISubtractionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IUnaryNegationOperators<IntPtr, IntPtr>, System::Numerics::IUnaryPlusOperators<IntPtr, IntPtr>, System::Runtime::Serialization::ISerializable
public value class IntPtr : IComparable<IntPtr>, IEquatable<IntPtr>, IParsable<IntPtr>, ISpanParsable<IntPtr>, IUtf8SpanParsable<IntPtr>, System::Numerics::IAdditionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IAdditiveIdentity<IntPtr, IntPtr>, System::Numerics::IBinaryInteger<IntPtr>, System::Numerics::IBinaryNumber<IntPtr>, System::Numerics::IBitwiseOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IComparisonOperators<IntPtr, IntPtr, bool>, System::Numerics::IDecrementOperators<IntPtr>, System::Numerics::IDivisionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IEqualityOperators<IntPtr, IntPtr, bool>, System::Numerics::IIncrementOperators<IntPtr>, System::Numerics::IMinMaxValue<IntPtr>, System::Numerics::IModulusOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IMultiplicativeIdentity<IntPtr, IntPtr>, System::Numerics::IMultiplyOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::INumber<IntPtr>, System::Numerics::INumberBase<IntPtr>, System::Numerics::IShiftOperators<IntPtr, int, IntPtr>, System::Numerics::ISignedNumber<IntPtr>, System::Numerics::ISubtractionOperators<IntPtr, IntPtr, IntPtr>, System::Numerics::IUnaryNegationOperators<IntPtr, IntPtr>, System::Numerics::IUnaryPlusOperators<IntPtr, IntPtr>, System::Runtime::Serialization::ISerializable
public value class IntPtr : IEquatable<IntPtr>, System::Runtime::Serialization::ISerializable
public value class IntPtr : System::Runtime::Serialization::ISerializable
public struct IntPtr
public readonly struct IntPtr : IComparable, IComparable<IntPtr>, IEquatable<IntPtr>, IFormattable, System.Runtime.Serialization.ISerializable
public readonly struct IntPtr : IComparable, IComparable<IntPtr>, IEquatable<IntPtr>, ISpanFormattable, System.Runtime.Serialization.ISerializable
public readonly struct IntPtr : IComparable<IntPtr>, IEquatable<IntPtr>, IParsable<IntPtr>, ISpanParsable<IntPtr>, System.Numerics.IAdditionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IAdditiveIdentity<IntPtr,IntPtr>, System.Numerics.IBinaryInteger<IntPtr>, System.Numerics.IBinaryNumber<IntPtr>, System.Numerics.IBitwiseOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IComparisonOperators<IntPtr,IntPtr,bool>, System.Numerics.IDecrementOperators<IntPtr>, System.Numerics.IDivisionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IEqualityOperators<IntPtr,IntPtr,bool>, System.Numerics.IIncrementOperators<IntPtr>, System.Numerics.IMinMaxValue<IntPtr>, System.Numerics.IModulusOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IMultiplicativeIdentity<IntPtr,IntPtr>, System.Numerics.IMultiplyOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.INumber<IntPtr>, System.Numerics.INumberBase<IntPtr>, System.Numerics.IShiftOperators<IntPtr,int,IntPtr>, System.Numerics.ISignedNumber<IntPtr>, System.Numerics.ISubtractionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IUnaryNegationOperators<IntPtr,IntPtr>, System.Numerics.IUnaryPlusOperators<IntPtr,IntPtr>, System.Runtime.Serialization.ISerializable
public readonly struct IntPtr : IComparable<IntPtr>, IEquatable<IntPtr>, IParsable<IntPtr>, ISpanParsable<IntPtr>, IUtf8SpanParsable<IntPtr>, System.Numerics.IAdditionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IAdditiveIdentity<IntPtr,IntPtr>, System.Numerics.IBinaryInteger<IntPtr>, System.Numerics.IBinaryNumber<IntPtr>, System.Numerics.IBitwiseOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IComparisonOperators<IntPtr,IntPtr,bool>, System.Numerics.IDecrementOperators<IntPtr>, System.Numerics.IDivisionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IEqualityOperators<IntPtr,IntPtr,bool>, System.Numerics.IIncrementOperators<IntPtr>, System.Numerics.IMinMaxValue<IntPtr>, System.Numerics.IModulusOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IMultiplicativeIdentity<IntPtr,IntPtr>, System.Numerics.IMultiplyOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.INumber<IntPtr>, System.Numerics.INumberBase<IntPtr>, System.Numerics.IShiftOperators<IntPtr,int,IntPtr>, System.Numerics.ISignedNumber<IntPtr>, System.Numerics.ISubtractionOperators<IntPtr,IntPtr,IntPtr>, System.Numerics.IUnaryNegationOperators<IntPtr,IntPtr>, System.Numerics.IUnaryPlusOperators<IntPtr,IntPtr>, System.Runtime.Serialization.ISerializable
public struct IntPtr : IEquatable<IntPtr>, System.Runtime.Serialization.ISerializable
public readonly struct IntPtr : IEquatable<IntPtr>, System.Runtime.Serialization.ISerializable
[System.Serializable]
public struct IntPtr : System.Runtime.Serialization.ISerializable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct IntPtr : System.Runtime.Serialization.ISerializable
public struct IntPtr : System.Runtime.Serialization.ISerializable
type nativeint = struct
type nativeint = struct
interface IFormattable
interface ISerializable
type nativeint = struct
interface ISpanFormattable
interface IFormattable
interface ISerializable
type nativeint = struct
interface IFormattable
interface IParsable<nativeint>
interface ISpanFormattable
interface ISpanParsable<nativeint>
interface IAdditionOperators<nativeint, nativeint, nativeint>
interface IAdditiveIdentity<nativeint, nativeint>
interface IBinaryInteger<nativeint>
interface IBinaryNumber<nativeint>
interface IBitwiseOperators<nativeint, nativeint, nativeint>
interface IComparisonOperators<nativeint, nativeint, bool>
interface IEqualityOperators<nativeint, nativeint, bool>
interface IDecrementOperators<nativeint>
interface IDivisionOperators<nativeint, nativeint, nativeint>
interface IIncrementOperators<nativeint>
interface IModulusOperators<nativeint, nativeint, nativeint>
interface IMultiplicativeIdentity<nativeint, nativeint>
interface IMultiplyOperators<nativeint, nativeint, nativeint>
interface INumber<nativeint>
interface INumberBase<nativeint>
interface ISubtractionOperators<nativeint, nativeint, nativeint>
interface IUnaryNegationOperators<nativeint, nativeint>
interface IUnaryPlusOperators<nativeint, nativeint>
interface IShiftOperators<nativeint, int, nativeint>
interface IMinMaxValue<nativeint>
interface ISignedNumber<nativeint>
interface ISerializable
type nativeint = struct
interface IFormattable
interface IParsable<nativeint>
interface ISpanFormattable
interface ISpanParsable<nativeint>
interface IAdditionOperators<nativeint, nativeint, nativeint>
interface IAdditiveIdentity<nativeint, nativeint>
interface IBinaryInteger<nativeint>
interface IBinaryNumber<nativeint>
interface IBitwiseOperators<nativeint, nativeint, nativeint>
interface IComparisonOperators<nativeint, nativeint, bool>
interface IEqualityOperators<nativeint, nativeint, bool>
interface IDecrementOperators<nativeint>
interface IDivisionOperators<nativeint, nativeint, nativeint>
interface IIncrementOperators<nativeint>
interface IModulusOperators<nativeint, nativeint, nativeint>
interface IMultiplicativeIdentity<nativeint, nativeint>
interface IMultiplyOperators<nativeint, nativeint, nativeint>
interface INumber<nativeint>
interface INumberBase<nativeint>
interface ISubtractionOperators<nativeint, nativeint, nativeint>
interface IUnaryNegationOperators<nativeint, nativeint>
interface IUnaryPlusOperators<nativeint, nativeint>
interface IUtf8SpanFormattable
interface IUtf8SpanParsable<nativeint>
interface IShiftOperators<nativeint, int, nativeint>
interface IMinMaxValue<nativeint>
interface ISignedNumber<nativeint>
interface ISerializable
type nativeint = struct
interface ISerializable
[<System.Serializable>]
type nativeint = struct
interface ISerializable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type nativeint = struct
interface ISerializable
Public Structure IntPtr
Public Structure IntPtr
Implements IComparable, IComparable(Of IntPtr), IEquatable(Of IntPtr), IFormattable, ISerializable
Public Structure IntPtr
Implements IComparable, IComparable(Of IntPtr), IEquatable(Of IntPtr), ISerializable, ISpanFormattable
Public Structure IntPtr
Implements IAdditionOperators(Of IntPtr, IntPtr, IntPtr), IAdditiveIdentity(Of IntPtr, IntPtr), IBinaryInteger(Of IntPtr), IBinaryNumber(Of IntPtr), IBitwiseOperators(Of IntPtr, IntPtr, IntPtr), IComparable(Of IntPtr), IComparisonOperators(Of IntPtr, IntPtr, Boolean), IDecrementOperators(Of IntPtr), IDivisionOperators(Of IntPtr, IntPtr, IntPtr), IEqualityOperators(Of IntPtr, IntPtr, Boolean), IEquatable(Of IntPtr), IIncrementOperators(Of IntPtr), IMinMaxValue(Of IntPtr), IModulusOperators(Of IntPtr, IntPtr, IntPtr), IMultiplicativeIdentity(Of IntPtr, IntPtr), IMultiplyOperators(Of IntPtr, IntPtr, IntPtr), INumber(Of IntPtr), INumberBase(Of IntPtr), IParsable(Of IntPtr), ISerializable, IShiftOperators(Of IntPtr, Integer, IntPtr), ISignedNumber(Of IntPtr), ISpanParsable(Of IntPtr), ISubtractionOperators(Of IntPtr, IntPtr, IntPtr), IUnaryNegationOperators(Of IntPtr, IntPtr), IUnaryPlusOperators(Of IntPtr, IntPtr)
Public Structure IntPtr
Implements IAdditionOperators(Of IntPtr, IntPtr, IntPtr), IAdditiveIdentity(Of IntPtr, IntPtr), IBinaryInteger(Of IntPtr), IBinaryNumber(Of IntPtr), IBitwiseOperators(Of IntPtr, IntPtr, IntPtr), IComparable(Of IntPtr), IComparisonOperators(Of IntPtr, IntPtr, Boolean), IDecrementOperators(Of IntPtr), IDivisionOperators(Of IntPtr, IntPtr, IntPtr), IEqualityOperators(Of IntPtr, IntPtr, Boolean), IEquatable(Of IntPtr), IIncrementOperators(Of IntPtr), IMinMaxValue(Of IntPtr), IModulusOperators(Of IntPtr, IntPtr, IntPtr), IMultiplicativeIdentity(Of IntPtr, IntPtr), IMultiplyOperators(Of IntPtr, IntPtr, IntPtr), INumber(Of IntPtr), INumberBase(Of IntPtr), IParsable(Of IntPtr), ISerializable, IShiftOperators(Of IntPtr, Integer, IntPtr), ISignedNumber(Of IntPtr), ISpanParsable(Of IntPtr), ISubtractionOperators(Of IntPtr, IntPtr, IntPtr), IUnaryNegationOperators(Of IntPtr, IntPtr), IUnaryPlusOperators(Of IntPtr, IntPtr), IUtf8SpanParsable(Of IntPtr)
Public Structure IntPtr
Implements IEquatable(Of IntPtr), ISerializable
Public Structure IntPtr
Implements ISerializable
- 継承
- 属性
- 実装
-
IComparable IComparable<IntPtr> IEquatable<IntPtr> IFormattable ISerializable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<IntPtr> IParsable<TSelf> ISpanParsable<IntPtr> ISpanParsable<TSelf> IAdditionOperators<IntPtr,IntPtr,IntPtr> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<IntPtr,IntPtr> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<IntPtr> IBinaryNumber<IntPtr> IBinaryNumber<TSelf> IBitwiseOperators<IntPtr,IntPtr,IntPtr> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<IntPtr,IntPtr,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<IntPtr> IDecrementOperators<TSelf> IDivisionOperators<IntPtr,IntPtr,IntPtr> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<IntPtr,IntPtr,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<IntPtr> IIncrementOperators<TSelf> IMinMaxValue<IntPtr> IModulusOperators<IntPtr,IntPtr,IntPtr> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<IntPtr,IntPtr> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<IntPtr,IntPtr,IntPtr> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<IntPtr> INumber<TSelf> INumberBase<IntPtr> INumberBase<TSelf> IShiftOperators<IntPtr,Int32,IntPtr> IShiftOperators<TSelf,Int32,TSelf> ISignedNumber<IntPtr> ISubtractionOperators<IntPtr,IntPtr,IntPtr> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<IntPtr,IntPtr> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<IntPtr,IntPtr> IUnaryPlusOperators<TSelf,TSelf> IUtf8SpanFormattable IUtf8SpanParsable<IntPtr> IUtf8SpanParsable<TSelf>
例
次の例では、マネージド ポインターを使用して配列内の文字を反転します。 オブジェクトを String 初期化し、その長さを取得すると、次の処理が行われます。
メソッドを Marshal.StringToHGlobalAnsi 呼び出して、Unicode 文字列を ANSI (1 バイト) 文字としてアンマネージド メモリにコピーします。 メソッドは、 IntPtr アンマネージ文字列の先頭を指す オブジェクトを返します。 Visual Basic の例では、このポインターを直接使用します。C++、F#、C# の例では、バイトへのポインターにキャストされます。
メソッドを Marshal.AllocHGlobal 呼び出して、アンマネージド文字列が占めるのと同じバイト数を割り当てます。 メソッドは、 IntPtr アンマネージ メモリ ブロックの先頭を指す オブジェクトを返します。 Visual Basic の例では、このポインターを直接使用します。C++、F#、C# の例では、バイトへのポインターにキャストされます。
Visual Basic の例では、ANSI 文字列の長さに等しい という名前
offset
の変数を定義しています。 ANSI 文字列の次の文字がコピーされるアンマネージド メモリへのオフセットを決定するために使用されます。 その開始値は文字列の長さであるため、コピー操作では、文字列の先頭からメモリ ブロックの末尾に文字がコピーされます。C#、F#、C++ の例では、 メソッドを呼び出 ToPointer して、文字列の開始アドレスとアンマネージ メモリ ブロックへのアンマネージ ポインターを取得し、文字列の長さより 1 つ小さいポインターを ANSI 文字列の開始アドレスに追加します。 アンマネージド文字列ポインターが文字列の末尾を指すようになったため、コピー操作では、文字列の末尾からメモリ ブロックの先頭に文字がコピーされます。
ループを使用して、文字列からアンマネージ メモリ ブロックに各文字をコピーします。
Visual Basic の例では、 メソッドを Marshal.ReadByte(IntPtr, Int32) 呼び出して、マネージド ポインターから ANSI 文字列への指定されたオフセットにあるバイト (または 1 バイト文字) を読み取ります。 オフセットは、ループの反復ごとにインクリメントされます。 次に、 メソッドを Marshal.WriteByte(IntPtr, Int32, Byte) 呼び出して、アンマネージ メモリ ブロックの開始アドレスに を加えて定義されたメモリ アドレスにバイトを書き込みます
offset
。 次に、 をデクリメントしますoffset
。C#、F#、C++ の例では、コピー操作を実行し、アンマネージド ANSI 文字列内の次の場所のアドレスへのポインターをデクリメントし、アンマネージ ブロック内の次のアドレスへのポインターをインクリメントします。
すべての例では、 を Marshal.PtrToStringAnsi 呼び出して、コピーした ANSI 文字列を含むアンマネージ メモリ ブロックをマネージド Unicode String オブジェクトに変換します。
元の文字列と反転した文字列を表示した後、すべての例で メソッドを FreeHGlobal 呼び出して、アンマネージド ANSI 文字列とアンマネージド メモリ ブロックに割り当てられたメモリを解放します。
using namespace System;
using namespace System::Runtime::InteropServices;
class NotTooSafeStringReverse
{
public:
static void Main()
{
String^ stringA = "I seem to be turned around!";
int copylen = stringA->Length;
// Allocate HGlobal memory for source and destination strings
IntPtr sptr = Marshal::StringToHGlobalAnsi(stringA);
IntPtr dptr = Marshal::AllocHGlobal(copylen + 1);
char *src = (char *)sptr.ToPointer();
char *dst = (char *)dptr.ToPointer();
if (copylen > 0)
{
// set the source pointer to the end of the string
// to do a reverse copy.
src += copylen - 1;
while (copylen-- > 0)
{
*dst++ = *src--;
}
*dst = 0;
}
String^ stringB = Marshal::PtrToStringAnsi(dptr);
Console::WriteLine("Original:\n{0}\n", stringA);
Console::WriteLine("Reversed:\n{0}", stringB);
// Free HGlobal memory
Marshal::FreeHGlobal(dptr);
Marshal::FreeHGlobal(sptr);
}
};
int main()
{
NotTooSafeStringReverse::Main();
}
// The progam has the following output:
//
// Original:
// I seem to be turned around!
//
// Reversed:
// !dnuora denrut eb ot mees I
using System;
using System.Runtime.InteropServices;
class NotTooSafeStringReverse
{
static public void Main()
{
string stringA = "I seem to be turned around!";
int copylen = stringA.Length;
// Allocate HGlobal memory for source and destination strings
IntPtr sptr = Marshal.StringToHGlobalAnsi(stringA);
IntPtr dptr = Marshal.AllocHGlobal(copylen + 1);
// The unsafe section where byte pointers are used.
unsafe
{
byte *src = (byte *)sptr.ToPointer();
byte *dst = (byte *)dptr.ToPointer();
if (copylen > 0)
{
// set the source pointer to the end of the string
// to do a reverse copy.
src += copylen - 1;
while (copylen-- > 0)
{
*dst++ = *src--;
}
*dst = 0;
}
}
string stringB = Marshal.PtrToStringAnsi(dptr);
Console.WriteLine("Original:\n{0}\n", stringA);
Console.WriteLine("Reversed:\n{0}", stringB);
// Free HGlobal memory
Marshal.FreeHGlobal(dptr);
Marshal.FreeHGlobal(sptr);
}
}
// The progam has the following output:
//
// Original:
// I seem to be turned around!
//
// Reversed:
// !dnuora denrut eb ot mees I
#nowarn "9"
open System.Runtime.InteropServices
open FSharp.NativeInterop
[<EntryPoint>]
let main _ =
let stringA = "I seem to be turned around!"
let mutable copylen = stringA.Length
// Allocate HGlobal memory for source and destination strings
let sptr = Marshal.StringToHGlobalAnsi stringA
let dptr = Marshal.AllocHGlobal(copylen + 1)
let mutable src: byte nativeptr = sptr.ToPointer() |> NativePtr.ofVoidPtr
let mutable dst: byte nativeptr = dptr.ToPointer() |> NativePtr.ofVoidPtr
if copylen > 0 then
// set the source pointer to the end of the string
// to do a reverse copy.
src <-
NativePtr.toNativeInt src + nativeint (copylen - 1)
|> NativePtr.ofNativeInt
while copylen > 0 do
copylen <- copylen - 1
NativePtr.read src |> NativePtr.write dst
dst <- NativePtr.toNativeInt dst + 1n |> NativePtr.ofNativeInt
src <- NativePtr.toNativeInt src - 1n |> NativePtr.ofNativeInt
NativePtr.write dst 0uy
let stringB = Marshal.PtrToStringAnsi dptr
printfn $"Original:\n{stringA}\n"
printfn $"Reversed:\n{stringB}"
// Free HGlobal memory
Marshal.FreeHGlobal dptr
Marshal.FreeHGlobal sptr
0
// The progam has the following output:
//
// Original:
// I seem to be turned around!
//
// Reversed:
// !dnuora denrut eb ot mees I
Imports System.Runtime.InteropServices
Public Module Example
Public Sub Main()
Dim stringA As String = "I seem to be turned around!"
Dim copylen As Integer = stringA.Length
' Allocate HGlobal memory for source and destination strings
Dim sptr As IntPtr = Marshal.StringToHGlobalAnsi(stringA)
Dim dptr As IntPtr = Marshal.AllocHGlobal(copylen)
Dim offset As Integer = copylen - 1
For ctr As Integer = 0 To copylen - 1
Dim b As Byte = Marshal.ReadByte(sptr, ctr)
Marshal.WriteByte(dptr, offset, b)
offset -= 1
Next
Dim stringB As String = Marshal.PtrToStringAnsi(dptr)
Console.WriteLine("Original:{1}{0}{1}", stringA, vbCrLf)
Console.WriteLine("Reversed:{1}{0}{1}", stringB, vbCrLf)
' Free HGlobal memory
Marshal.FreeHGlobal(dptr)
Marshal.FreeHGlobal(sptr)
End Sub
End Module
' The example displays the following output:
' Original:
' I seem to be turned around!
'
' Reversed:
' !dnuora denrut eb ot mees I
注釈
型は IntPtr 、ポインターと同じサイズの整数に設計されています。 つまり、この型のインスタンスは、32 ビット プロセスでは 32 ビット、64 ビット プロセスでは 64 ビットである必要があります。
型は IntPtr 、ポインターをサポートする言語で使用でき、ポインターをサポートする言語とサポートしていない言語間でデータを参照する一般的な手段として使用できます。
IntPtr オブジェクトを使用してハンドルを保持することもできます。 たとえば、 の IntPtr インスタンスは、 クラスでファイル ハンドルを System.IO.FileStream 保持するために広範囲に使用されます。
Note
ポインターまたはハンドルとして を使用すると IntPtr 、エラーが発生しやすく、安全ではありません。 これは単なる整数型であり、同じサイズであるため、ポインターとハンドルのインターチェンジ形式として使用できます。 ポインターをサポートしていない言語にデータを渡すなど、特定のインターチェンジ要件以外では、ポインターを表すために正しく型指定されたポインターを使用し、 SafeHandle ハンドルを表すために使用する必要があります。
この型は、 を実装します ISerializable。 .NET 5 以降のバージョンでは、この型は インターフェイスも実装します IFormattable 。 .NET 7 以降のバージョンでは、この型は、IMinMaxValue<TSelf>および ISignedNumber<TSelf> インターフェイスも実装IBinaryInteger<TSelf>します。
バージョン 9.0 以降の C# では、組 nint
み込み型を使用してネイティブ サイズの整数を定義できます。 この型は、 型によって IntPtr 内部的に表され、整数型に適した演算と変換を提供します。 詳細については、「 nint 型と nuint 型」を参照してください。
バージョン 11 以降の C# では、.NET 7 以降のランタイムを対象とする場合、 nint
は のエイリアス IntPtr と同じ方法 int
で の Int32エイリアスです。
コンストラクター
IntPtr(Int32) |
指定した 32 ビット符号付き整数を使用して の新しいインスタンス IntPtr を初期化します。 |
IntPtr(Int64) |
指定した 64 ビット符号付き整数を使用して の新しいインスタンス IntPtr を初期化します。 |
IntPtr(Void*) |
指定されていない型へのポインターを使用して、IntPtr の新しいインスタンスを初期化します。 |
フィールド
Zero |
0 に初期化された符号付き整数を表す読み取り専用フィールド。 |
プロパティ
MaxValue |
可能な最大値を IntPtr取得します。 |
MinValue |
の可能な限り小さい値を IntPtr取得します。 |
Size |
このインスタンスのサイズを取得します。 |
メソッド
Abs(IntPtr) |
値の絶対を計算します。 |
Add(IntPtr, Int32) |
符号付き整数にオフセットを追加します。 |
Clamp(IntPtr, IntPtr, IntPtr) |
値を包括的な最小値と最大値にクランプします。 |
CompareTo(IntPtr) |
現在のインスタンスを同じ型の別のオブジェクトと比較し、現在のインスタンスの並べ替え順序での位置が、比較対象のオブジェクトと比べて前か、後か、または同じかを示す整数を返します。 |
CompareTo(Object) |
現在のインスタンスを同じ型の別のオブジェクトと比較し、現在のインスタンスの並べ替え順序での位置が、比較対象のオブジェクトと比べて前か、後か、または同じかを示す整数を返します。 |
CopySign(IntPtr, IntPtr) |
値の符号を別の値の符号にコピーします。 |
CreateChecked<TOther>(TOther) |
現在の型のインスタンスを値から作成し、現在の型の表現可能な範囲外にある値に対してオーバーフロー例外をスローします。 |
CreateSaturating<TOther>(TOther) |
現在の型のインスタンスを値から作成し、現在の型の表現可能な範囲外の値を飽和させます。 |
CreateTruncating<TOther>(TOther) |
現在の型のインスタンスを値から作成し、現在の型の表現可能な範囲外の値を切り捨てます。 |
DivRem(IntPtr, IntPtr) |
2 つの値の商と剰余を計算します。 |
Equals(IntPtr) |
現在のオブジェクトが、同じ型の別のオブジェクトと等しいかどうかを示します。 |
Equals(Object) |
このインスタンスが指定されたオブジェクトに等しいかどうかを示す値を返します。 |
GetHashCode() |
このインスタンスのハッシュ コードを返します。 |
IsEvenInteger(IntPtr) |
値が偶数の整数を表すかどうかを判断します。 |
IsNegative(IntPtr) |
値が負かどうかを判断します。 |
IsOddInteger(IntPtr) |
値が奇数の整数を表すかどうかを判断します。 |
IsPositive(IntPtr) |
値が正かどうかを判断します。 |
IsPow2(IntPtr) |
値が 2 の累乗であるかどうかを判断します。 |
LeadingZeroCount(IntPtr) |
値の先頭の 0 の数を計算します。 |
Log2(IntPtr) |
値の log2 を計算します。 |
Max(IntPtr, IntPtr) |
2 つの値を比較して、より大きいコンピューティングを行います。 |
MaxMagnitude(IntPtr, IntPtr) |
2 つの値を比較して、より大きいコンピューティングを行います。 |
Min(IntPtr, IntPtr) |
2 つの値を比較して、より小さいコンピューティングを行います。 |
MinMagnitude(IntPtr, IntPtr) |
2 つの値を比較して、より小さいコンピューティングを行います。 |
Parse(ReadOnlySpan<Byte>, IFormatProvider) |
UTF-8 文字のスパンを値に解析します。 |
Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider) |
UTF-8 文字のスパンを値に解析します。 |
Parse(ReadOnlySpan<Char>, IFormatProvider) |
文字のスパンを値に解析します。 |
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
指定したスタイルとカルチャ固有の形式の数値の文字表現の読み取り専用スパンを、符号付きネイティブ整数に変換します。 |
Parse(String) |
数値の文字列表現を、等価の符号付きネイティブ整数に変換します。 |
Parse(String, IFormatProvider) |
指定されたカルチャに固有の書式による数値の文字列形式を、それと等価な符号付きネイティブ整数に変換します。 |
Parse(String, NumberStyles) |
指定したスタイルの数値の文字列形式を、それと等しい符号付きネイティブ整数に変換します。 |
Parse(String, NumberStyles, IFormatProvider) |
指定されたスタイルとカルチャに固有の書式による数値の文字列形式を、それと等価な符号付きネイティブ整数に変換します。 |
PopCount(IntPtr) |
値に設定されているビット数を計算します。 |
RotateLeft(IntPtr, Int32) |
指定した量だけ値を左に回転します。 |
RotateRight(IntPtr, Int32) |
指定した量だけ値を右方向に回転します。 |
Sign(IntPtr) |
値の符号を計算します。 |
Subtract(IntPtr, Int32) |
符号付き整数からオフセットを減算します。 |
ToInt32() |
このインスタンスの値を 32 ビット符号付き整数に変換します。 |
ToInt64() |
このインスタンスの値を 64 ビット符号付き整数に変換します。 |
ToPointer() |
このインスタンスの値を指定されていない型のポインターに変換します。 |
ToString() |
現在の IntPtr オブジェクトの数値を等価の文字列形式に変換します。 |
ToString(IFormatProvider) |
このインスタンスの数値を、指定した書式およびカルチャ固有の書式情報を使用して、それと等価な文字列形式に変換します。 |
ToString(String) |
現在の IntPtr オブジェクトの数値を等価の文字列形式に変換します。 |
ToString(String, IFormatProvider) |
指定された書式を使用して現在のインスタンスの値を書式設定します。 |
TrailingZeroCount(IntPtr) |
値の末尾の 0 の数を計算します。 |
TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
現在のインスタンスの値を UTF-8 として指定されたバイトスパンに書式設定しようとします。 |
TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
現在のインスタンスの値を、指定された文字数のスパンに書式設定しようとします。 |
TryParse(ReadOnlySpan<Byte>, IFormatProvider, IntPtr) |
UTF-8 文字のスパンを値に解析しようとします。 |
TryParse(ReadOnlySpan<Byte>, IntPtr) |
数値の文字列表現を含む UTF-8 文字スパンを、等価の符号付き整数に変換しようとします。 |
TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, IntPtr) |
UTF-8 文字のスパンを値に解析しようとします。 |
TryParse(ReadOnlySpan<Char>, IFormatProvider, IntPtr) |
文字列を値に解析しようとします。 |
TryParse(ReadOnlySpan<Char>, IntPtr) |
数値の文字表現の読み取り専用スパンを、等価の符号付きネイティブ整数に変換します。 戻り値は、変換が成功したかどうかを示します。 |
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, IntPtr) |
指定したスタイルとカルチャ固有の形式の数値の文字表現の読み取り専用スパンを、符号付きネイティブ整数に相当する形式に変換します。 戻り値は、変換が成功したかどうかを示します。 |
TryParse(String, IFormatProvider, IntPtr) |
文字列を値に解析しようとします。 |
TryParse(String, IntPtr) |
数値の文字列表現を等価の符号付きネイティブ整数に変換します。 戻り値は、変換が成功したかどうかを示します。 |
TryParse(String, NumberStyles, IFormatProvider, IntPtr) |
指定されたスタイルとカルチャに固有の書式による数値の文字列形式を、それと等価な符号付きネイティブ整数に変換します。 戻り値は、変換が成功したかどうかを示します。 |
演算子
Addition(IntPtr, Int32) |
符号付き整数にオフセットを追加します。 |
Equality(IntPtr, IntPtr) |
IntPtr の 2 つの指定したインスタンスが等しいかどうかを判断します。 |
Explicit(Int32 to IntPtr) |
32 ビット符号付き整数の値を IntPtr に変換します。 |
Explicit(Int64 to IntPtr) |
64 ビット符号付き整数の値を IntPtr に変換します。 |
Explicit(IntPtr to Int32) |
指定した IntPtr の値を 32 ビット符号付き整数に変換します。 |
Explicit(IntPtr to Int64) |
指定した IntPtr の値を 64 ビット符号付き整数に変換します。 |
Explicit(IntPtr to Void*) |
指定した IntPtr の値を指定されていない型のポインターに変換します。 この API は、CLS に準拠していません。 |
Explicit(Void* to IntPtr) |
指定されていない型の指定のポインターを IntPtr に変換します。 この API は、CLS に準拠していません。 |
Inequality(IntPtr, IntPtr) |
IntPtr の 2 つの指定したインスタンスが等しいかどうかを判断します。 |
Subtraction(IntPtr, Int32) |
符号付き整数からオフセットを減算します。 |
明示的なインターフェイスの実装
適用対象
スレッド セーフ
この型はスレッド セーフです。
こちらもご覧ください
フィードバック
フィードバックの送信と表示