Question WriteProcessMemory Help

DavidTiger

New member
Joined
Jul 24, 2009
Messages
4
Programming Experience
5-10
HI, Im having trouble writing different values types to memory, for a particular exe

Using the code below will allow me to write a value of 4 Bytes correctly but I also need to write a Float value.

VB.NET:
    Public Declare Function WriteProcessMemory Lib "kernel32" _
    (ByVal hProcess As Integer, _
     ByVal lpBaseAddress As Integer, _
     ByRef lpBuffer As Long, _
     ByVal nSize As Integer, _
     ByRef lpNumberOfBytesWritten As Integer) As Integer

Which this code allows me to write a Float value correctly
VB.NET:
    Public Declare Function WriteProcessMemory Lib "kernel32" _
    (ByVal hProcess As Integer, _
     ByVal lpBaseAddress As Integer, _
     ByRef lpBuffer As Single, _
     ByVal nSize As Integer, _
     ByRef lpNumberOfBytesWritten As Integer) As Integer

Is there any way I can have both of these, to allow me to write 4 byte integers as well as Float Values?

-Tiger
 
Last edited:
Sorry triple post but I have found a solution, and though I'd post incase anyone else needs help with this...

To Write different values in the same program, but you can only declare the WriteProcessMemory function once well why not use alias's :rolleyes:

VB.NET:
    Private Declare Function WriteMemoryInteger Lib "KERNEL32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, _
    ByRef Value As Integer, Optional ByVal Size As Integer = 4, Optional ByRef BytesWritten As Integer = 0) As Integer

    Private Declare Function WriteMemorySingle Lib "KERNEL32" Alias "WriteProcessMemory" (ByVal Handle As Integer, ByVal Address As Integer, _
    ByRef Value As Single, Optional ByVal Size As Integer = 4, Optional ByRef BytesWritten As Integer = 0) As Single

That will allow you to write an Integer value as well as a Float (Single) value

Cheers
-Tiger

Mods: You can lock this thread now..
 
Back
Top