Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Toolhelp32ReadProcessMemory (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool Toolhelp32ReadProcessMemory(uint th32ProcessID,
   IntPtr lpBaseAddress, [Out] byte [] lpBuffer, UIntPtr cbRead,
   IntPtr lpNumberOfBytesRead);

VB.NET Signature:

  <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
  Friend Function Toolhelp32ReadProcessMemory(ByVal th32ProcessID As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal cbRead As Integer, ByRef lpNumberOfBytesRead As Integer) As Integer
  End Function
  <DllImport("kernel32.dll", CharSet:=CharSet.Ansi)> _
  Friend Function Toolhelp32ReadProcessMemory(ByVal th32ProcessID As Integer, ByVal lpBaseAddress As Integer, <Out()> ByVal lpBuffer As Text.StringBuilder, ByVal cbRead As Integer, ByRef lpNumberOfBytesRead As Integer) As Integer
  End Function

User-Defined Types:

None.

Notes:

In VB.NET, the 'CharSet' field of the 'DllImport' attribute needed to be set to 'Ansi' instead of 'Auto', and 'lpBuffer' should be defined as 'System.Text.StringBuilder' instead of 'Byte()' when returning a string.

Tips & Tricks:

Please add some!

Sample Code:

  Private Function GetControlProgID(ByVal iProcessID As Integer, ByVal iBaseAddress As Integer, ByVal iBlkSize As Integer) As String
    Dim iInfoPtr As Integer, iStrPtr As Integer
    Dim sWork As New Text.StringBuilder(iBlkSize)

    Try
      Toolhelp32ReadProcessMemory(iProcessID, iBaseAddress + 44, iInfoPtr, 4, 0) ' Get pointer to class info...
      Toolhelp32ReadProcessMemory(iProcessID, iInfoPtr + 36, iStrPtr, 4, 0) ' Get pointer to Control Class string...
      If iStrPtr <> 0 Then Toolhelp32ReadProcessMemory(iProcessID, iStrPtr, sWork, iBlkSize, 0)
      If (sWork.ToString & "  ").Substring(0, 2) <> "VB" Then
    Return ""
      Else
    Return sWork.ToString
      End If
    Catch ex As Exception
      Return ""
    End Try

  End Function

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions