Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:18:00+00:00 2026-05-26T08:18:00+00:00

I have Private Declare Function ReadProcessMemory Lib kernel32 Alias ReadProcessMemory (ByVal hProcess As Integer,

  • 0

I have

Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer

But I also need

Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Single, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer

And some other variations. So, as in the example above, lpBuffer as Single instead of Integer. How can I achieve this?

UPDATE: Alrighty, now I’m doing this:

Imports System.Math
Imports System.Threading
Imports System.Runtime.InteropServices

Public Class Form1

'Declare ReadProcessMemory with lpBuffer As IntPtr
Private Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As IntPtr, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer

'This is the function I am now having trouble with
Public Function memfloat(ByVal address As Long, ByVal processHandle As IntPtr)
        Dim floatvalueinmemory As Single
        ReadProcessMemory(processHandle, address, floatvalueinmemory, 4, 0)
        Dim letstryagain As Single 'floatvalueinmemory didn't give the desired result, so going to try to TryParse
        Single.TryParse(floatvalueinmemory, letstryagain)
        Return CStr(letstryagain) 'returns the same result as floatvalueinmemory did
    End Function

End Class

Partial Public Class NativeMethods
    <DllImport("user32.dll")> _
    Public Shared Function ReadProcessMemory(ByVal hProcess As System.IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As System.IntPtr, ByVal nSize As UInteger, ByVal lpNumberOfBytesRead As IntPtr) As Boolean
    End Function
End Class

The memfloat function used to return something like “-75,48196”, now it returns something like “-1,012555E+09” (the actual values don’t match, just using these as an example), this is why I wanted to declare multiple times in the first place.. how do I convert from the IntPtr to a Single ?

What does work is:

Public Function memstring(ByVal address As Long, ByVal length As Int32, ByVal processHandle As IntPtr)
    Dim stringinmemory As Long
    Dim ret1 As Byte() = Nothing
    Dim tStr(length) As Char
    Dim retStr As String = ""
    For i As Int32 = 0 To length - 1
        ReadProcessMemory(processHandle, address + i, stringinmemory, 1, 0)
        ret1 = BitConverter.GetBytes(stringinmemory)
        tStr(i) = System.Text.Encoding.ASCII.GetString(ret1) : retStr += tStr(i)
    Next
    Return retStr
End Function

This correctly returns the memory value as string. So yeah, now it’s just the Single that’s causing issues.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:18:01+00:00Added an answer on May 26, 2026 at 8:18 am

    You are using the Alias keyword anyway, so take advantage of it:

    Private Declare Function ReadProcessMemoryInt Lib "kernel32" _
        Alias "ReadProcessMemory" (ByVal hProcess As Integer, _
                                   ByVal lpBaseAddress As Integer, _
                                   ByRef lpBuffer As Integer, _
                                   ByVal nSize As Integer, _
                                   ByRef lpNumberOfBytesWritten As Integer) As Integer
    
    Private Declare Function ReadProcessMemorySingle Lib "kernel32" _
        Alias "ReadProcessMemory" (ByVal hProcess As Integer, _
                                   ByVal lpBaseAddress As Integer, _
                                   ByRef lpBuffer As Single, _
                                   ByVal nSize As Integer, _
                                   ByRef lpNumberOfBytesWritten As Integer) As Integer
    

    The name you give to the function can be arbitrary. Only the Alias name must match the name in the library. In your code, you can refer to ReadProcessMemoryInt and ReadProcessMemorySingle (or whatever name you chose).

    (Note: I didn’t check whether you are actually using the API correctly, I’ve just answered your question about how to define the same API function twice with different signatures.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the current code: Public Declare Function FindWindow Lib user32.dll Alias FindWindowA (ByVal
I have the following declaration in a Module: Private Declare Function gzopen Lib ZLIB.DLL
Right now, I have to do this private delegate void set(int obj); //declare the
I have a situaion in which I want to declare a class member function
Private Function getFoo(ByVal _FileInfo As FileInfo) As foo() Dim provider As New ExcelStorage(GetType(foo)) provider.StartRow
If I have a java class which is package-private (declared with class, not public
I have a NumericStepper declared as a UIComponent: <![CDATA[ private var component:UIComponent; component =
Here's the c# code that I have: private double get806Fees (Loan loan) { Loan.Fee.Items
Why can NHibernate create a proxy for classes with properties that have private setters
I have a private const int defined in a C# class. I want compilation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.