this is my code so far:
#include "iostream"
#include "Windows.h"
#include "stdio.h"
using namespace std;
int main() {
HWND hWnd = FindWindow(NULL,TEXT("Vovoid VSXu Artiste 0.4.0 [Windows 64-bit]"));
if (hWnd == 0) {
cerr << "Cannot find window "<< endl;
}
else {
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
cout << "Found Window at "<<pId << endl;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
HMODULE hModule = GetModuleHandle(TEXT("sound.rtaudio.dll"));
if (hProc == 0) {
cerr << "Cannot open process." << endl;
}else if(hModule==0){
DWORD error = GetLastError();
cerr << "could not find Module -> error: " <<error<< endl;
}
else {
float val = 0;
int addr = 0x04D40000 + 0x19098;//should be sound.rtaudio.dll+ 0x19098
while(TRUE){
int suc = ReadProcessMemory(hProc, (LPVOID)addr, &val, (DWORD)sizeof(val), NULL);
if (suc > 0) {
cout << "Success reading " << val << " of " << hex << addr << endl;
system("cls");
}
else {
DWORD error = GetLastError();
cerr << "fail " << error << endl;
}
}
}
CloseHandle(hProc);
}
cin.get();
return 0;
}
I want to read the VU (sound card volume) value of the VSXu Artiste sound visualisation programm with C++ and with the help of Cheat Engine. It works perfectly fine with ReadProcessMemory(hProc, (LPVOID)addr, &val, (DWORD)sizeof(val), NULL);
until you re-open VSXu. This is pretty obvious, because the address of my value in Cheat Engine is "sound.rtaudio.dll+19098" and the DLL loads to a "random" address.
In Cheat Engine you can simply press Ctrl+G in the memory viewer and type the name of the DLL to find its base address. I have already tried the GetModuleHandle method in C++ without success:
HMODULE hModule = GetModuleHandle(TEXT("sound.rtaudio.dll"));
Has anyone an idea how to get the base address of the dll with C++?
Cheat Engine screenshot: http://oi57.tinypic.com/331k7sw.jpg
Kind regards,
Robert
The problem is I suppose because you are calling GetModuleHandle within your own process. The solution you can try is to use:
GetModuleInformation, it will return base address in MODULEINFO as:
lpBaseOfDll
The load address of the module.
To get process and module handle you can use sample code from here:Enumerating All Modules For a Process