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 호출하여 유니코드 문자열을 관리되지 않는 메모리에 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 하여 문자열의 시작 주소와 관리되지 않는 메모리 블록에 대한 관리되지 않는 포인터를 가져와서 ANSI 문자열의 시작 주소에 문자열 길이보다 작은 포인터를 추가합니다. 이제 관리되지 않는 문자열 포인터가 문자열의 끝을 가리키기 때문에 복사 작업은 문자열의 끝에서 메모리 블록의 시작 부분에 문자를 복사합니다.
루프를 사용하여 문자열의 각 문자를 관리되지 않는 메모리 블록으로 복사합니다.
Visual Basic 예제에서는 메서드를 Marshal.ReadByte(IntPtr, Int32) 호출하여 관리되는 포인터에서 ANSI 문자열로 지정된 오프셋에서 바이트(또는 1 바이트 문자)를 읽습니다. 오프셋은 루프를 반복할 때마다 증가합니다. 그런 다음 메서드를 Marshal.WriteByte(IntPtr, Int32, Byte) 호출하여 비관리형 메모리 블록의 시작 주소와 에 정의된 메모리
offset
주소에 바이트를 씁니다. 그런 다음, 를 감소합니다offset
.C#, F# 및 C++ 예제에서는 복사 작업을 수행한 다음 관리되지 않는 ANSI 문자열에서 다음 위치의 주소에 대한 포인터를 감소시키고 관리되지 않는 블록의 다음 주소로 포인터를 증분합니다.
모든 예제에서는 를 호출 Marshal.PtrToStringAnsi 하여 복사된 ANSI 문자열을 포함하는 관리되지 않는 메모리 블록을 관리형 유니코드 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 포인터와 크기가 같은 정수로 설계되었습니다. 즉, 이 유형의 instance 32비트 프로세스에서 32비트, 64비트 프로세스에서 64비트여야 합니다.
형식은 IntPtr 포인터를 지원하는 언어와 포인터를 지원하지 않는 언어 간의 데이터를 참조하는 일반적인 수단으로 사용할 수 있습니다.
IntPtr 개체를 사용하여 핸들을 보관할 수도 있습니다. 예를 들어 인스턴스는 파일 핸들을 IntPtr 보유하기 위해 클래스에서 System.IO.FileStream 광범위하게 사용됩니다.
참고
포인터 또는 핸들로 사용하는 IntPtr 것은 오류가 발생하기 쉽고 안전하지 않습니다. 크기가 같기 때문에 포인터 및 핸들의 교환 형식으로 사용할 수 있는 정수 형식일 뿐입니다. 포인터를 지원하지 않는 언어로 데이터를 전달하는 것과 같은 특정 교환 요구 사항 외에는 포인터를 나타내는 데 올바르게 형식화된 포인터를 사용해야 하며 SafeHandle 핸들을 나타내는 데 사용해야 합니다.
이 형식은 를 ISerializable구현합니다. .NET 5 이상 버전에서 이 형식은 인터페이스도 구현 IFormattable 합니다. .NET 7 이상 버전에서 이 형식은 , IMinMaxValue<TSelf>및 ISignedNumber<TSelf> 인터페이스도 구현IBinaryInteger<TSelf>합니다.
버전 9.0부터 시작하는 C#에서 기본 제공 nint
형식을 사용하여 네이티브 크기의 정수 정의할 수 있습니다. 이 형식은 내부적으로 형식으로 IntPtr 표시되며 정수 형식에 적합한 작업 및 변환을 제공합니다. 자세한 내용은 nint 및 nuint 형식을 참조하세요.
버전 11부터 .NET 7 이상 런타임 nint
을 대상으로 하는 C#에서 는 의 별칭 IntPtr 과 동일한 방식으로 int
에 대한 Int32별칭입니다.
생성자
IntPtr(Int32) |
지정된 32비트 부가 정수 사용의 IntPtr 새 instance 초기화합니다. |
IntPtr(Int64) |
지정된 64비트 부가 정수 사용의 IntPtr 새 instance 초기화합니다. |
IntPtr(Void*) |
알 수 없는 형식의 지정된 포인터를 사용하여 IntPtr의 새 인스턴스를 초기화합니다. |
필드
Zero |
0으로 초기화된 서명된 정수(integer)를 나타내는 읽기 전용 필드입니다. |
속성
MaxValue |
의 가능한 가장 큰 값을 가져옵니다 IntPtr. |
MinValue |
의 가능한 가장 작은 값을 가져옵니다 IntPtr. |
Size |
이 인스턴스의 크기를 가져옵니다. |
메서드
Abs(IntPtr) |
값의 절대값을 계산합니다. |
Add(IntPtr, Int32) |
부인 정수에 오프셋을 추가합니다. |
Clamp(IntPtr, IntPtr, IntPtr) |
값을 포괄 최소값 및 최대값으로 고정합니다. |
CompareTo(IntPtr) |
현재 인스턴스와 동일한 형식의 다른 개체를 비교하고 정렬 순서에서 현재 인스턴스의 위치가 다른 개체보다 앞인지, 뒤인지 또는 동일한지를 나타내는 정수를 반환합니다. |
CompareTo(Object) |
현재 인스턴스와 동일한 형식의 다른 개체를 비교하고 정렬 순서에서 현재 인스턴스의 위치가 다른 개체보다 앞인지, 뒤인지 또는 동일한지를 나타내는 정수를 반환합니다. |
CopySign(IntPtr, IntPtr) |
값의 기호를 다른 값의 기호에 복사합니다. |
CreateChecked<TOther>(TOther) |
값에서 현재 형식의 instance 만들어 현재 형식의 표현 가능한 범위를 벗어나는 값에 대해 오버플로 예외를 throw합니다. |
CreateSaturating<TOther>(TOther) |
값에서 현재 형식의 instance 만들어 현재 형식의 표현 가능한 범위를 벗어나는 모든 값을 채도합니다. |
CreateTruncating<TOther>(TOther) |
값에서 현재 형식의 instance 만들어 현재 형식의 표현 가능한 범위를 벗어나는 값을 잘리게 합니다. |
DivRem(IntPtr, IntPtr) |
두 값의 몫과 나머지를 계산합니다. |
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) |
두 값을 더 큰 컴퓨팅과 비교합니다. |
MaxMagnitude(IntPtr, IntPtr) |
두 값을 더 큰 컴퓨팅과 비교합니다. |
Min(IntPtr, IntPtr) |
두 값을 더 작은 컴퓨팅과 비교합니다. |
MinMagnitude(IntPtr, IntPtr) |
두 값을 더 작은 컴퓨팅과 비교합니다. |
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) |
현재 instance 값의 형식을 제공된 바이트 범위로 UTF-8로 지정하려고 시도합니다. |
TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) |
현재 instance 값의 형식을 제공된 문자 범위로 지정하려고 시도합니다. |
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의 지정된 두 인스턴스가 같은지를 확인합니다. |
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의 지정된 두 인스턴스가 다른지를 확인합니다. |
Subtraction(IntPtr, Int32) |
부속 정수에서 오프셋을 뺍니다. |
명시적 인터페이스 구현
적용 대상
스레드 보안
이 형식은 스레드로부터 안전합니다.
추가 정보
피드백
다음에 대한 사용자 의견 제출 및 보기