 |
| Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book:
Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 12th, 2008, 05:15 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
No, I meant this:
Code:
Dim sString = System.Text.Encoding.UTF8.GetString(...)
Any Dim statement, with or without an assignation (an "= ...") should include a type for the variable being dimensioned.
In VB 6 an untyped Dim was always a Variant. But .NET has no Variants.
I believe a null string is similar to "". The second argument is an index, and should be either 0 or 1 to start with the first byte (and probably 0, since it is an index, not a starting character; the terminology implies 0-based).
So for this function call you should have
Code:
. . . = System.Text.Encoding.UTF8.GetString(MapNameByte, 0, 16)
Number of Bytes Written will be filled in by the ReadProcessMemory() function, so you'll know how many bytes were transferred. You should supply a variable here that can receive the value from the functionâwhatever that type is in the documentation for the function.
Consider: If you set aside 1K of memory, and initialized all of it to = 0, then called this function and it only wrote 1019 bytes, you would have no way to know whether the last 5 bytes of the set asid earea got zeros written, or not. If you know the number of bytes written that is no longer an issue.
|
|

September 13th, 2008, 04:16 PM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, but Im still being thrown the same error now, after changing this bit of code:
Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'.
My Dim:
Dim MapNameByte(16) As Byte
and using it as "MapNameByte" in ReadProcessMemory, results in the error.
|
|

September 15th, 2008, 11:40 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I just looked at a posting at Google Groups. That posting indicates that the buffer should be a string... Doesn't make much sense, but it's worth a try:
Code:
Dim MapNameByte(16) As Byte
' becomes
Dim MapNameByte(16) As String
' The function call would be the same:
ReadProcessMemory(hProc, addr, MapNameByte, 16, vbNull)
|
|

September 15th, 2008, 02:21 PM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I now have:
Code:
Dim MapNameByte As String
ReadProcessMemory(hproc, addy, MapNameByte, 16, vbNull)
Dim sString = System.Text.Encoding.Unicode.GetString(MapNameByte)
This results in an error on 'MapNameByte' in GetString():
Value of type 'String' cannot be converted to '1-dimensional array of Byte'.
Else, if I do:
Code:
Dim MapNameByte(16) As String
ReadProcessMemory(hproc, addy, MapNameByte, 16, vbNull)
Dim sString = System.Text.Encoding.Unicode.GetString(MapNameByte)
It results in 2 errors, first one on 'MapNameByte' in readprocessmemory:
Value of type '1-dimensional array of String' cannot be converted to 'Byte'.
And another error on 'MapNameByte' in GetString():
Value of type '1-dimensional array of String' cannot be converted to '1-dimensional array of Byte' because 'String' is not derived from 'Byte'.
I'm quite lost now, and don't know what else to do to fix this.
|
|

September 15th, 2008, 04:10 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
What is your declaration for ReadProcessMemory?
How are you coming up with the value of addy?
I am going to try to duplicate this, so I need a little more info.
What is the process you are trying to read the memory of?
With the declaration, an idea of the type of process, and how you are trying to implement this, letâs see what I can find.
|
|

September 16th, 2008, 12:37 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
These are my declarations:
Code:
Public Const PROCESS_VM_READ As Integer = &H10
Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
The type of process I'm reading from is a game: "dfbhd.exe". I'm attempting to make a Servermanager, for me and a few friends to use. I want it to display the current mapname in a textbox "txt_mapname". The "addy", or rather "address" is where I'm trying to read from. I currently have:
Code:
Dim addy
addy = &H7C2B44
I have 'addy' in an If statement, since I recently found out there's multiple versions of the game, and I want it to work with both versions.
I hope this helps. Thanks in advance.
|
|

September 23rd, 2008, 09:07 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I was wondering if you have figured out what I might have done wrong ? I'm still busy almost dialy trying to change things, variables and functions but it still doesnt seem to work.
|
|

October 8th, 2008, 07:56 AM
|
|
Authorized User
|
|
Join Date: Aug 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please help, or atleast tell me what I'm doing is not possible. Thanks.
|
|
 |