System.Runtime.InteropServices.Marshal Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.InteropServices
Summary
Provides a collection of methods pertaining to allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types.
C# Syntax:
public sealed class Marshal
Remarks
The static methods defined on the Marshal class are essential to working with unmanaged code. The methods defined here are typically used by advanced developers building custom marshalers who need to provide a bridge between the managed and unmanaged programming models.

For example, the System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi (not supported on the shared source CLI) method copies the ANSI characters from a specified string (in managed heap) to a buffer in unmanaged heap. It also allocates the target heap of the right size. For example:

          				String s = "Hello";
          				IntPtr p = Marshal.StringToHGlobalAnsi(s);
          			
        
See also:
System.Runtime.InteropServices Namespace

System.Runtime.InteropServices.Marshal Member List:

Public Fields
SystemDefaultCharSize Represents the default character size on the system. The default is 2 for Unicode systems and 1 for ANSI systems.
SystemMaxDBCSCharSize The maximum size of a DBCS character.
Public Methods
AllocHGlobal Overloaded:
AllocHGlobal(int cb)

Allocates memory from the unmanaged native heap of the process using GlobalAlloc.
AllocHGlobal Overloaded:
AllocHGlobal(IntPtr cb)

Allocates memory from the unmanaged native heap of the process using GlobalAlloc.
Copy Overloaded:
Copy(byte[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed byte array to an unmanaged memory pointer.
Copy Overloaded:
Copy(char[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed char array to an unmanaged memory pointer.
Copy Overloaded:
Copy(double[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed double array to an unmanaged memory pointer.
Copy Overloaded:
Copy(short[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed short array to an unmanaged memory pointer.
Copy Overloaded:
Copy(int[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed int array to an unmanaged memory pointer.
Copy Overloaded:
Copy(long[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed long array to an unmanaged memory pointer.
Copy Overloaded:
Copy(IntPtr source, byte[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed byte array.
Copy Overloaded:
Copy(IntPtr source, char[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed char array.
Copy Overloaded:
Copy(IntPtr source, double[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed double array.
Copy Overloaded:
Copy(IntPtr source, short[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed short array.
Copy Overloaded:
Copy(IntPtr source, int[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed int array.
Copy Overloaded:
Copy(IntPtr source, long[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed long array.
Copy Overloaded:
Copy(IntPtr source, float[] destination, int startIndex, int length)

Copies data from an unmanaged memory pointer to a managed float array.
Copy Overloaded:
Copy(float[] source, int startIndex, IntPtr destination, int length)

Copies data from a managed float array to an unmanaged memory pointer.
DestroyStructure Frees all substructures pointed to by the specified native memory block.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
FreeHGlobal Frees memory previously allocated from the unmanaged native heap of the process with Marshal.AllocHGlobal.
GetExceptionCode Retrieves a code that identifies the type of the exception that occurred.
GetExceptionPointers Retrieves a machine independent description of an exception, and information about the machine state that existed for the thread when the exception occurred.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetHINSTANCE Returns the HInstance for the specified module.
GetHRForException Converts the specified exception to an HRESULT.
GetHRForLastWin32Error Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal.
GetLastWin32Error Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
NumParamBytes Calculates the number of bytes required to hold the parameters for the specified method.
OffsetOf Returns the field offset of the unmanaged form of the class.
Prelink Executes the one-time method set up tasks without calling the method.
PrelinkAll Performs a pre-link check for all methods on a class.
PtrToStringAnsi Overloaded:
PtrToStringAnsi(IntPtr ptr)

Copies an ANSI string to a managed String object. Widens each ANSI character to Unicode.
PtrToStringAnsi Overloaded:
PtrToStringAnsi(IntPtr ptr, int len)

Copies a specified number of characters from an ANSI string to a managed String object. Widens each ANSI character to Unicode if needed.
PtrToStringAuto Overloaded:
PtrToStringAuto(IntPtr ptr)

Copies a string stored in native heap to a managed String object.
PtrToStringAuto Overloaded:
PtrToStringAuto(IntPtr ptr, int len)

Copies a specified number of characters from a string stored in native heap to a managed String object.
PtrToStringUni Overloaded:
PtrToStringUni(IntPtr ptr)

Copies a Unicode string stored in native heap to a managed String object.
PtrToStringUni Overloaded:
PtrToStringUni(IntPtr ptr, int len)

Copies a specified number of characters from a Unicode string stored in native heap to a managed String object.
PtrToStructure Overloaded:
PtrToStructure(IntPtr ptr, object structure)

Marshals data from an unmanaged block of memory pointed to a managed object.
PtrToStructure Overloaded:
PtrToStructure(IntPtr ptr, Type structureType)

Marshals data from an unmanaged block of memory to a newly allocated object of the specified type.
ReadByte Overloaded:
ReadByte(IntPtr ptr)

Reads a single byte from an unmanaged pointer.
ReadByte Overloaded:
ReadByte(IntPtr ptr, int ofs)

Reads a single byte from an unmanaged pointer.
ReadByte Overloaded:
ReadByte(in object ptr, int ofs)

Reads a single byte from an unmanaged pointer.
ReadInt16 Overloaded:
ReadInt16(IntPtr ptr)

Reads a 16-bit integer from native heap.
ReadInt16 Overloaded:
ReadInt16(IntPtr ptr, int ofs)

Reads a 16-bit integer from native heap.
ReadInt16 Overloaded:
ReadInt16(in object ptr, int ofs)

Reads a 16-bit integer from native heap.
ReadInt32 Overloaded:
ReadInt32(IntPtr ptr)

Reads a 32-bit integer from native heap.
ReadInt32 Overloaded:
ReadInt32(IntPtr ptr, int ofs)

Reads a 32-bit integer from native heap.
ReadInt32 Overloaded:
ReadInt32(in object ptr, int ofs)

Reads a 32-bit integer from native heap.
ReadInt64 Overloaded:
ReadInt64(IntPtr ptr)

Reads a 64-bit integer from native heap.
ReadInt64 Overloaded:
ReadInt64(IntPtr ptr, int ofs)

Reads a 64-bit integer from native heap.
ReadInt64 Overloaded:
ReadInt64(in object ptr, int ofs)

Reads a 64-bit integer from native heap.
ReadIntPtr Overloaded:
ReadIntPtr(IntPtr ptr)

Reads a processor native sized integer from native heap.
ReadIntPtr Overloaded:
ReadIntPtr(IntPtr ptr, int ofs)

Reads a processor native sized integer from native heap.
ReadIntPtr Overloaded:
ReadIntPtr(in object ptr, int ofs)

Reads a processor native sized integer from native heap.
SizeOf Overloaded:
SizeOf(object structure)

Returns the unmanaged size of an object in bytes.
SizeOf Overloaded:
SizeOf(Type t)

Returns the unmanaged size of a type in bytes.
StructureToPtr Marshals data from a managed object to an unmanaged block of memory.
ThrowExceptionForHR Overloaded:
ThrowExceptionForHR(int errorCode)

Throws an exception with a specific HRESULT value.
ThrowExceptionForHR Overloaded:
ThrowExceptionForHR(int errorCode, IntPtr errorInfo)

Throws an exception with a specific HRESULT.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
UnsafeAddrOfPinnedArrayElement Gets the address of the element at the specified index inside the specified array.
WriteByte Overloaded:
WriteByte(IntPtr ptr, byte val)

Writes a single byte value into native heap.
WriteByte Overloaded:
WriteByte(IntPtr ptr, int ofs, byte val)

Writes a single byte value into native heap.
WriteByte Overloaded:
WriteByte(in object ptr, int ofs, byte val)

Writes a single byte value into native heap.
WriteInt16 Overloaded:
WriteInt16(IntPtr ptr, char val)

Writes a 16-bit integer value into native heap.
WriteInt16 Overloaded:
WriteInt16(IntPtr ptr, short val)

Writes a 16-bit integer value into native heap.
WriteInt16 Overloaded:
WriteInt16(IntPtr ptr, int ofs, char val)

Writes a 16-bit integer value into native heap.
WriteInt16 Overloaded:
WriteInt16(IntPtr ptr, int ofs, short val)

Writes a 16-bit integer value into native heap.
WriteInt16 Overloaded:
WriteInt16(in object ptr, int ofs, char val)

Writes a 16-bit integer value into native heap.
WriteInt16 Overloaded:
WriteInt16(in object ptr, int ofs, short val)

Writes a 16-bit integer value into native heap.
WriteInt32 Overloaded:
WriteInt32(IntPtr ptr, int val)

Writes a 32-bit integer value into native heap.
WriteInt32 Overloaded:
WriteInt32(IntPtr ptr, int ofs, int val)

Writes a 32-bit integer value into native heap.
WriteInt32 Overloaded:
WriteInt32(in object ptr, int ofs, int val)

Writes a 32-bit integer value into native heap.
WriteInt64 Overloaded:
WriteInt64(IntPtr ptr, long val)

Writes a 64-bit integer value into native heap.
WriteInt64 Overloaded:
WriteInt64(IntPtr ptr, int ofs, long val)

Writes a 64-bit integer value into native heap.
WriteInt64 Overloaded:
WriteInt64(in object ptr, int ofs, long val)

Writes a 64-bit integer value into native heap.
WriteIntPtr Overloaded:
WriteIntPtr(IntPtr ptr, IntPtr val)

Writes a processor native sized integer value into native heap.
WriteIntPtr Overloaded:
WriteIntPtr(IntPtr ptr, int ofs, IntPtr val)

Writes a processor native sized integer value into native heap.
WriteIntPtr Overloaded:
WriteIntPtr(in object ptr, int ofs, IntPtr val)

Writes a processor native sized integer value into native heap.
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.Marshal Member Details

Field: SystemDefaultCharSize
Summary
Represents the default character size on the system. The default is 2 for Unicode systems and 1 for ANSI systems.
C# Syntax:
public static readonly int SystemDefaultCharSize;

Return to top


Field: SystemMaxDBCSCharSize
Summary
The maximum size of a DBCS character.
C# Syntax:
public static readonly int SystemMaxDBCSCharSize;

Return to top


Overloaded Method: AllocHGlobal(
   int cb
)
Summary
Allocates memory from the unmanaged native heap of the process using GlobalAlloc.
C# Syntax:
public static IntPtr AllocHGlobal(
   int cb
);
Parameters:

cb

The number of bytes in memory required.

Return Value:
A pointer to the newly allocated memory. This memory must be released using Marshal.FreeHGlobal.
Exceptions
Exception Type Condition
OutOfMemoryException There is insufficient memory to satisfy the request.
Remarks
Refer to GlobalAlloc in the MSDN Library for additional details.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: AllocHGlobal(
   IntPtr cb
)
Summary
Allocates memory from the unmanaged native heap of the process using GlobalAlloc.
C# Syntax:
public static IntPtr AllocHGlobal(
   IntPtr cb
);
Parameters:

cb

The number of bytes in memory required.

Return Value:
A pointer to the newly allocated memory. This memory must be released using Marshal.FreeHGlobal.
Exceptions
Exception Type Condition
OutOfMemoryException There is insufficient memory to satisfy the request.
Remarks
Refer to GlobalAlloc in the MSDN Library for additional details.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   byte[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed byte array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   byte[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   char[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed char array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   char[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   double[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed double array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   double[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   short[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed short array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   short[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   int[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed int array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   int[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   long[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed long array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   long[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   byte[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed byte array.
C# Syntax:
public static void Copy(
   IntPtr source,
   byte[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   char[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed char array.
C# Syntax:
public static void Copy(
   IntPtr source,
   char[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   double[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed double array.
C# Syntax:
public static void Copy(
   IntPtr source,
   double[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   short[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed short array.
C# Syntax:
public static void Copy(
   IntPtr source,
   short[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   int[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed int array.
C# Syntax:
public static void Copy(
   IntPtr source,
   int[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   long[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed long array.
C# Syntax:
public static void Copy(
   IntPtr source,
   long[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   IntPtr source,
   float[] destination,
   int startIndex,
   int length
)
Summary
Copies data from an unmanaged memory pointer to a managed float array.
C# Syntax:
public static void Copy(
   IntPtr source,
   float[] destination,
   int startIndex,
   int length
);
Parameters:

source

The memory pointer to copy from.

destination

The array to copy to.

startIndex

The index into array where Copy should start.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: Copy(
   float[] source,
   int startIndex,
   IntPtr destination,
   int length
)
Summary
Copies data from a managed float array to an unmanaged memory pointer.
C# Syntax:
public static void Copy(
   float[] source,
   int startIndex,
   IntPtr destination,
   int length
);
Parameters:

source

The array to copy from.

startIndex

The index into array where Copy should start.

destination

The memory pointer to copy to.

length

The number of array elements to copy.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: DestroyStructure(
   IntPtr ptr,
   Type structuretype
)
Summary
Frees all substructures pointed to by the specified native memory block.
C# Syntax:
public static void DestroyStructure(
   IntPtr ptr,
   Type structuretype
);
Parameters:

ptr

A pointer to an unmanaged block of memory.

structuretype

A formatted class. This provides the layout information necessary to delete the buffer or buffers in ptr.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

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

Return to top


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

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

Return to top


Method: FreeHGlobal(
   IntPtr hglobal
)
Summary
Frees memory previously allocated from the unmanaged native heap of the process with Marshal.AllocHGlobal.
C# Syntax:
public static void FreeHGlobal(
   IntPtr hglobal
);
Parameters:

hglobal

The handle returned by the original matching call to Marshal.AllocHGlobal.

Exceptions
Exception Type Condition
ArgumentException There is any failure.
Remarks
Refer to GlobalFree in the MSDN Library for additional details.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetExceptionCode()
Summary
Retrieves a code that identifies the type of the exception that occurred.
C# Syntax:
public static int GetExceptionCode();
Return Value:
The type of the exception.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetExceptionPointers()
Summary
Retrieves a machine independent description of an exception, and information about the machine state that existed for the thread when the exception occurred.
C# Syntax:
public static IntPtr GetExceptionPointers();
Return Value:
An IntPtr to an EXCEPTION_POINTERS structure.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

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

Return to top


Method: GetHINSTANCE(
   Module m
)
Summary
Returns the HInstance for the specified module.
C# Syntax:
public static IntPtr GetHINSTANCE(
   Module m
);
Parameters:

m

The module whose HInstance is desired.

Return Value:
The HInstance for m; -1 if the module does not have an HInstance.
Remarks
Whether dynamic or in-memory, modules do not have an HInstance.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetHRForException(
   Exception e
)
Summary
Converts the specified exception to an HRESULT.
C# Syntax:
public static int GetHRForException(
   Exception e
);
Parameters:

e

The exception to convert to an HRESULT.

Return Value:
The HRESULT mapped to the supplied exception.
Remarks
This function also sets up an IErrorInfo interface for the exception that can be obtained by calling the GetErrorInfo COM API.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetHRForLastWin32Error()
Summary
Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal.
C# Syntax:
public static int GetHRForLastWin32Error();
Return Value:
The HRESULT corresponding to the last Win32 error code.
Remarks
The target function must have had the setLastError metadata flag set. The process for this varies depending upon the source language used.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: GetLastWin32Error()
Summary
Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set.
C# Syntax:
public static int GetLastWin32Error();
Return Value:
The last Win32 error code.
Remarks
This method exists because it is not safe to make a direct platform invoke call to GetLastError to obtain this information. The common language runtime might have made internal calls to API's that overwrite the operating system maintained GetLastError.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

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: NumParamBytes(
   MethodInfo m
)
Summary
Calculates the number of bytes required to hold the parameters for the specified method.
C# Syntax:
public static int NumParamBytes(
   MethodInfo m
);
Parameters:

m

The method to be checked.

Return Value:
The number of bytes required.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: OffsetOf(
   Type t,
   string fieldName
)
Summary
Returns the field offset of the unmanaged form of the class.
C# Syntax:
public static IntPtr OffsetOf(
   Type t,
   string fieldName
);
Parameters:

t

The specified class. This class must use the StructLayoutAttribute.

fieldName

The field within t.

Return Value:
The offset in bytes, for fieldName within the platform invoke-declared class t.
Exceptions
Exception Type Condition
ArgumentException The class cannot be exported as a structure.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: Prelink(
   MethodInfo m
)
Summary
Executes the one-time method set up tasks without calling the method.
C# Syntax:
public static void Prelink(
   MethodInfo m
);
Parameters:

m

The method to be checked.

Remarks
This action is performed automatically when the target method is invoked.

First-time tasks include checking to ensure that the platform invoke metadata is correctly formatted, that all the managed types are valid to have in a platform invoke function, locating and loading the unmanaged DLL into the process, and locating the entrypoint in the process.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: PrelinkAll(
   Type c
)
Summary
Performs a pre-link check for all methods on a class.
C# Syntax:
public static void PrelinkAll(
   Type c
);
Parameters:

c

The class whose methods are to be checked.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringAnsi(
   IntPtr ptr
)
Summary
Copies an ANSI string to a managed String object. Widens each ANSI character to Unicode.
C# Syntax:
public static string PtrToStringAnsi(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap of source string.

Return Value:
A managed String object that holds a copy of the native ANSI string.
Exceptions
Exception Type Condition
ArgumentException ptr is null.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringAnsi(
   IntPtr ptr,
   int len
)
Summary
Copies a specified number of characters from an ANSI string to a managed String object. Widens each ANSI character to Unicode if needed.
C# Syntax:
public static string PtrToStringAnsi(
   IntPtr ptr,
   int len
);
Parameters:

ptr

The address in native heap of source string.

len

The number of ANSI characters to copy.

Return Value:
A managed String object that holds a copy of the native ANSI string.
Exceptions
Exception Type Condition
ArgumentException ptr is null.

-or-

len is less than zero.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringAuto(
   IntPtr ptr
)
Summary
Copies a string stored in native heap to a managed String object.
C# Syntax:
public static string PtrToStringAuto(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap of source string.

Return Value:
A managed String object, that holds a copy of the native string.
Remarks
If the current platform is Unicode, each ANSI character is widened to a Unicode character and this method calls Marshal.PtrToStringUni. Otherwise this method calls Marshal.PtrToStringAnsi.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringAuto(
   IntPtr ptr,
   int len
)
Summary
Copies a specified number of characters from a string stored in native heap to a managed String object.
C# Syntax:
public static string PtrToStringAuto(
   IntPtr ptr,
   int len
);
Parameters:

ptr

The address in native heap of source string.

len

The number of characters to copy.

Return Value:
A managed String object that holds a copy of the native string.
Remarks
If the current platform is Unicode, each ANSI character is widened to a Unicode character and this method calls Marshal.PtrToStringUni. Otherwise this method calls Marshal.PtrToStringAnsi.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringUni(
   IntPtr ptr
)
Summary
Copies a Unicode string stored in native heap to a managed String object.
C# Syntax:
public static string PtrToStringUni(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap of source string

Return Value:
A managed String object, holding a copy of the native string.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStringUni(
   IntPtr ptr,
   int len
)
Summary
Copies a specified number of characters from a Unicode string stored in native heap to a managed String object.
C# Syntax:
public static string PtrToStringUni(
   IntPtr ptr,
   int len
);
Parameters:

ptr

The address in native heap of source string.

len

The number of Unicode characters to copy.

Return Value:
A managed String object that holds a copy of the native string.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStructure(
   IntPtr ptr,
   object structure
)
Summary
Marshals data from an unmanaged block of memory pointed to a managed object.
C# Syntax:
public static void PtrToStructure(
   IntPtr ptr,
   object structure
);
Parameters:

ptr

A pointer to an unmanaged block of memory.

structure

The object to which the data is to be copied. This must be an instance of a formatted class.

Remarks
This method does not support value types.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: PtrToStructure(
   IntPtr ptr,
   Type structureType
)
Summary
Marshals data from an unmanaged block of memory to a newly allocated object of the specified type.
C# Syntax:
public static object PtrToStructure(
   IntPtr ptr,
   Type structureType
);
Parameters:

ptr

A pointer to an unmanaged block of memory.

structureType

The type of object to be created. This type object must represent a formatted class or a value class.

Return Value:
A managed object containing the data pointed to by ptr.
Remarks
You can pass a value type to this method. The returned object is a boxed instance.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadByte(
   IntPtr ptr
)
Summary
Reads a single byte from an unmanaged pointer.
C# Syntax:
public static byte ReadByte(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap from which to read.

Return Value:
The byte read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadByte(
   IntPtr ptr,
   int ofs
)
Summary
Reads a single byte from an unmanaged pointer.
C# Syntax:
public static byte ReadByte(
   IntPtr ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap from which to read.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The byte read from ptr.

Return to top


Overloaded Method: ReadByte(
   in object ptr,
   int ofs
)
Summary
Reads a single byte from an unmanaged pointer.
C# Syntax:
public static byte ReadByte(
   in object ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap of source object.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The byte read from ptr.

Return to top


Overloaded Method: ReadInt16(
   IntPtr ptr
)
Summary
Reads a 16-bit integer from native heap.
C# Syntax:
public static short ReadInt16(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap from which to read.

Return Value:
The 16-bit integer read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadInt16(
   IntPtr ptr,
   int ofs
)
Summary
Reads a 16-bit integer from native heap.
C# Syntax:
public static short ReadInt16(
   IntPtr ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap from which to read.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The 16-bit integer read from ptr.

Return to top


Overloaded Method: ReadInt16(
   in object ptr,
   int ofs
)
Summary
Reads a 16-bit integer from native heap.
C# Syntax:
public static short ReadInt16(
   in object ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap of source object

ofs

An additional byte offset, added to ptr before reading

Return Value:
The 16-bit integer read from ptr.

Return to top


Overloaded Method: ReadInt32(
   IntPtr ptr
)
Summary
Reads a 32-bit integer from native heap.
C# Syntax:
public static int ReadInt32(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap from which to read.

Return Value:
The 32-bit integer read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadInt32(
   IntPtr ptr,
   int ofs
)
Summary
Reads a 32-bit integer from native heap.
C# Syntax:
public static int ReadInt32(
   IntPtr ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap from which to read.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The 32-bit integer read from ptr.

Return to top


Overloaded Method: ReadInt32(
   in object ptr,
   int ofs
)
Summary
Reads a 32-bit integer from native heap.
C# Syntax:
public static int ReadInt32(
   in object ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap of source object.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The 32-bit integer read from ptr.

Return to top


Overloaded Method: ReadInt64(
   IntPtr ptr
)
Summary
Reads a 64-bit integer from native heap.
C# Syntax:
public static long ReadInt64(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap from which to read.

Return Value:
The 64-bit integer read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadInt64(
   IntPtr ptr,
   int ofs
)
Summary
Reads a 64-bit integer from native heap.
C# Syntax:
public static long ReadInt64(
   IntPtr ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap from which to read.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The 64-bit integer read from ptr.

Return to top


Overloaded Method: ReadInt64(
   in object ptr,
   int ofs
)
Summary
Reads a 64-bit integer from native heap.
C# Syntax:
public static long ReadInt64(
   in object ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap of source object.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The 64-bit integer read from ptr.

Return to top


Overloaded Method: ReadIntPtr(
   IntPtr ptr
)
Summary
Reads a processor native sized integer from native heap.
C# Syntax:
public static IntPtr ReadIntPtr(
   IntPtr ptr
);
Parameters:

ptr

The address in native heap from which to read.

Return Value:
The IntPtr read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadIntPtr(
   IntPtr ptr,
   int ofs
)
Summary
Reads a processor native sized integer from native heap.
C# Syntax:
public static IntPtr ReadIntPtr(
   IntPtr ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap from which to read.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The IntPtr read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ReadIntPtr(
   in object ptr,
   int ofs
)
Summary
Reads a processor native sized integer from native heap.
C# Syntax:
public static IntPtr ReadIntPtr(
   in object ptr,
   int ofs
);
Parameters:

ptr

The base address in native heap of source object.

ofs

An additional byte offset, added to ptr before reading.

Return Value:
The IntPtr read from ptr.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: SizeOf(
   object structure
)
Summary
Returns the unmanaged size of an object in bytes.
C# Syntax:
public static int SizeOf(
   object structure
);
Parameters:

structure

The object whose size is to be returned.

Return Value:
The size of structure in unmanaged code.
Exceptions
Exception Type Condition
ArgumentException structure is not a Marshal class.

-or-

structure is an array type.

NullReferenceException structure is null.
Remarks
The size returned is actually the size of the unmanaged object. The managed size of the object can differ. For character types, this is affected by the CharSet value applied to that class.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: SizeOf(
   Type t
)
Summary
Returns the unmanaged size of a type in bytes.
C# Syntax:
public static int SizeOf(
   Type t
);
Parameters:

t

The type whose size is to be returned.

Return Value:
The size of structure in unmanaged code.
Exceptions
Exception Type Condition
ArgumentException structure is not a Marshal class.

-or-

structure is an array type.

NullReferenceException structure is null.
Remarks
The size returned is actually the size of the unmanaged type. The managed size of the object can differ. For character types, this is affected by the CharSet value applied to that class.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: StructureToPtr(
   object structure,
   IntPtr ptr,
   bool fDeleteOld
)
Summary
Marshals data from a managed object to an unmanaged block of memory.
C# Syntax:
public static void StructureToPtr(
   object structure,
   IntPtr ptr,
   bool fDeleteOld
);
Parameters:

structure

A managed object holding the data to be marshaled. This object must be an instance of a formatted class.

ptr

A pointer to an unmanaged block of memory, which must be allocated before this method is called.

fDeleteOld

If true, Marshal.DestroyStructure will be called on ptr before this method executes. Note that passing false can lead to a memory leak.

Remarks
This method copies the contents of structure to the block of memory pointed to by ptr. If fDeleteOld is true, the buffer originally pointed to by ptr is deleted. This is accomplished by calling the appropriate delete API on the embedded pointer.StructureToPtr does this clean-up for every reference field specified in the mirrored managed class.

Suppose your unmanaged block of memory is pointed to by ptr. The layout of this block is described by a corresponding managed class structure.StructureToPtr marshals field values from a structure to a pointer. Suppose the ptr block includes a reference field, pointing to a string buffer currently holding "abc". Suppose the corresponding field on the managed side is a string holding "vwxyz". If you do not tell it otherwise, StructureToPtr allocates a new unmanaged buffer to hold "vwxyz", and hooks it up to the ptr block. This will cast the old buffer "abc" adrift without freeing it back to the unmanaged heap. You end up with an orphan buffer that represents a memory leak in your code. If you set the fDeleteOld bit true, StructureToPtr frees the buffer holding "abc" before going on to allocate a new buffer for "vwxyz".

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ThrowExceptionForHR(
   int errorCode
)
Summary
Throws an exception with a specific HRESULT value.
C# Syntax:
public static void ThrowExceptionForHR(
   int errorCode
);
Parameters:

errorCode

The HRESULT corresponding to the desired exception.

Remarks
This method creates an exception object for the specified HRESULT. Some HRESULT's map to well-defined exceptions, others do not map to a defined exception. If the HRESULT maps to a defined exception, ThrowExceptionForHR creates an instance of the exception and throws it. Otherwise, it creates an instance of COMException, initializes the error code field with the HRESULT, and throws that exception. When this method is invoked, it attemps to retrieve extra information regarding the error by using GetErrorInfo.

For more information, please see the existing documentation for GetErrorInfo in the MSDN library.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: ThrowExceptionForHR(
   int errorCode,
   IntPtr errorInfo
)
Summary
Throws an exception with a specific HRESULT.
C# Syntax:
public static void ThrowExceptionForHR(
   int errorCode,
   IntPtr errorInfo
);
Parameters:

errorCode

The HRESULT corresponding to the desired exception.

errorInfo

A pointer to the IErrorInfo interface provided by the COM object.

Remarks
This method creates an exception object for the specified HRESULT. Some HRESULT's map to well-defined exceptions, others do not map to a defined exception. If the HRESULT maps to a defined exception, ThrowExceptionForHR creates an instance of the exception and throws it. Otherwise, it creates an instance of COMException, initializes the error code field with the HRESULT, and throws that exception.errorInfo is used to retrieve extra information regarding the error.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

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

Return to top


Method: UnsafeAddrOfPinnedArrayElement(
   Array arr,
   int index
)
Summary
Gets the address of the element at the specified index inside the specified array.
C# Syntax:
public static IntPtr UnsafeAddrOfPinnedArrayElement(
   Array arr,
   int index
);
Parameters:

arr

The array containing the desired element.

index

The index in arr of the desired element.

Return Value:
The address of index inside arr.
Remarks
The array must be pinned using a GCHandle before it is passed to this method.
.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteByte(
   IntPtr ptr,
   byte val
)
Summary
Writes a single byte value into native heap.
C# Syntax:
public static void WriteByte(
   IntPtr ptr,
   byte val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to be written.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteByte(
   IntPtr ptr,
   int ofs,
   byte val
)
Summary
Writes a single byte value into native heap.
C# Syntax:
public static void WriteByte(
   IntPtr ptr,
   int ofs,
   byte val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteByte(
   in object ptr,
   int ofs,
   byte val
)
Summary
Writes a single byte value into native heap.
C# Syntax:
public static void WriteByte(
   in object ptr,
   int ofs,
   byte val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt16(
   IntPtr ptr,
   char val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   IntPtr ptr,
   char val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to be written.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteInt16(
   IntPtr ptr,
   short val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   IntPtr ptr,
   short val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteInt16(
   IntPtr ptr,
   int ofs,
   char val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   IntPtr ptr,
   int ofs,
   char val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt16(
   IntPtr ptr,
   int ofs,
   short val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   IntPtr ptr,
   int ofs,
   short val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt16(
   in object ptr,
   int ofs,
   char val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   in object ptr,
   int ofs,
   char val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt16(
   in object ptr,
   int ofs,
   short val
)
Summary
Writes a 16-bit integer value into native heap.
C# Syntax:
public static void WriteInt16(
   in object ptr,
   int ofs,
   short val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt32(
   IntPtr ptr,
   int val
)
Summary
Writes a 32-bit integer value into native heap.
C# Syntax:
public static void WriteInt32(
   IntPtr ptr,
   int val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteInt32(
   IntPtr ptr,
   int ofs,
   int val
)
Summary
Writes a 32-bit integer value into native heap.
C# Syntax:
public static void WriteInt32(
   IntPtr ptr,
   int ofs,
   int val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt32(
   in object ptr,
   int ofs,
   int val
)
Summary
Writes a 32-bit integer value into native heap.
C# Syntax:
public static void WriteInt32(
   in object ptr,
   int ofs,
   int val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt64(
   IntPtr ptr,
   long val
)
Summary
Writes a 64-bit integer value into native heap.
C# Syntax:
public static void WriteInt64(
   IntPtr ptr,
   long val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteInt64(
   IntPtr ptr,
   int ofs,
   long val
)
Summary
Writes a 64-bit integer value into native heap.
C# Syntax:
public static void WriteInt64(
   IntPtr ptr,
   int ofs,
   long val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteInt64(
   in object ptr,
   int ofs,
   long val
)
Summary
Writes a 64-bit integer value into native heap.
C# Syntax:
public static void WriteInt64(
   in object ptr,
   int ofs,
   long val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

Return to top


Overloaded Method: WriteIntPtr(
   IntPtr ptr,
   IntPtr val
)
Summary
Writes a processor native sized integer value into native heap.
C# Syntax:
public static void WriteIntPtr(
   IntPtr ptr,
   IntPtr val
);
Parameters:

ptr

The address in native heap from which to write.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteIntPtr(
   IntPtr ptr,
   int ofs,
   IntPtr val
)
Summary
Writes a processor native sized integer value into native heap.
C# Syntax:
public static void WriteIntPtr(
   IntPtr ptr,
   int ofs,
   IntPtr val
);
Parameters:

ptr

The base address in native heap from which to write.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Overloaded Method: WriteIntPtr(
   in object ptr,
   int ofs,
   IntPtr val
)
Summary
Writes a processor native sized integer value into native heap.
C# Syntax:
public static void WriteIntPtr(
   in object ptr,
   int ofs,
   IntPtr val
);
Parameters:

ptr

The base address in native heap of the target object.

ofs

An additional byte offset, added to ptr before writing.

val

The value to write.

.NET Framework Security:
SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.

Return to top


Top of page

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