WriteIntPtr Method
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Marshal.WriteIntPtr Method

Writes a processor native sized integer value to unmanaged memory.

Overload List

Writes a processor native sized integer value into unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteIntPtr(IntPtr, IntPtr)
[C#] public static void WriteIntPtr(IntPtr, IntPtr);
[C++] public: static void WriteIntPtr(IntPtr, IntPtr);
[JScript] public static function WriteIntPtr(IntPtr, IntPtr);

Writes a processor native sized integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteIntPtr(IntPtr, Integer, IntPtr)
[C#] public static void WriteIntPtr(IntPtr, int, IntPtr);
[C++] public: static void WriteIntPtr(IntPtr, int, IntPtr);
[JScript] public static function WriteIntPtr(IntPtr, int, IntPtr);

Writes a processor native sized integer value to unmanaged memory.

[Visual Basic] Overloads Public Shared Sub WriteIntPtr(Object, Integer, IntPtr)
[C#] public static void WriteIntPtr(object, int, IntPtr);
[C++] public: static void WriteIntPtr(Object, int, IntPtr);
[JScript] public static function WriteIntPtr(Object, int, IntPtr);

Example

[Visual Basic, C#] The following example compares two ways of interacting with an unmanaged C-style IntPtr array. The WriteIntPtr method provides direct access to the element values of the array, setting its ten elements to the values 1 through 10.

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of WriteIntPtr. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to set the 10 elements of the C-style unmanagedArray
Dim newArray As IntPtr(9)
Marshal.Copy(unmanagedArray, newArray, 0, 10)
For i = 0 To newArray.Length
  newArray(i) = i+1
Next i
Marshal.Copy(newArray, 0, unmanagedArray, 10)
' Another way to set the 10 elements of the C-style unmanagedArray
For i = 0 To 10
  Marshal.WriteIntPtr(unmanagedArray, i, i+1)
Next i
      
[C#] 
IntPtr unmanagedArray = ...;
// One way to set the 10 elements of the C-style unmanagedArray
byte [] newArray = new IntPtr[10];
Marshal.Copy(unmanagedArray, newArray, 0, 10);
for (int i = 0; i < newArray.Length; i++)
  newArray[i] = i+1;
Marshal.Copy(newArray, 0, unmanagedArray, 10);
// Another way to set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
  Marshal.WriteIntPtr(unmanagedArray, i, i+1);
      

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace

Show:
© 2016 Microsoft