This documentation is archived and is not being maintained.

Marshal.ReadInt64 Method (IntPtr, Int32)

.NET Framework 1.1

Reads a 64-bit signed integer from unmanaged memory.

[Visual Basic]
Overloads Public Shared Function ReadInt64( _
   ByVal ptr As IntPtr, _
   ByVal ofs As Integer _
) As Long
[C#]
public static long ReadInt64(
 IntPtr ptr,
 int ofs
);
[C++]
public: static __int64 ReadInt64(
 IntPtr ptr,
 int ofs
);
[JScript]
public static function ReadInt64(
   ptr : IntPtr,
 ofs : int
) : long;

Parameters

ptr
The base address in unmanaged memory from which to read.
ofs
An additional byte offset, added to the ptr parameter before reading.

Return Value

The 64-bit signed integer read from the ptr parameter.

Exceptions

Exception Type Condition
ArgumentException ptr is not a recognized format.

Remarks

ReadInt64 enables direct interaction with an unmanaged 64-bit signed array, eliminating the expense of copying an entire unmanaged array (using Marshal.Copy) to a separate managed array before reading its element values.

Note   This method uses SecurityAction.LinkDemand to prevent it from being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.

Example

[Visual Basic, C#] The following example compares two ways of interacting with an unmanaged C-style Int64 array. The ReadInt64 method provides direct access to the array's element values.

[Visual Basic] 
Dim unmanagedArray As IntPtr = ...
Dim i As Integer
' One way to print the 10 elements of the C-style unmanagedArray
Dim newArray As Int64(9)
Marshal.Copy(unmanagedArray, newArray, 0, 10)
For i = 0 To newArray.Length
  Console.WriteLine(newArray(i))
Next i
' Another way to print the 10 elements of the C-style unmanagedArray
For i = 0 To 10
  Console.WriteLine(Marshal.ReadInt64(unmanagedArray, i))
Next i
   
[C#] 
IntPtr unmanagedArray = ...;
// One way to print the 10 elements of the C-style unmanagedArray
byte [] newArray = new Int64[10];
Marshal.Copy(unmanagedArray, newArray, 0, 10);
for (int i = 0; i < newArray.Length; i++)
  Console.WriteLine(newArray[i]);
// Another way to print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
  Console.WriteLine(Marshal.ReadInt64(unmanagedArray, i));
   

[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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace | Marshal.ReadInt64 Overload List | Copy | ReadByte

Show: