Ive been working on making a memory reader / writer for awhile now and ive ran into some problems.
I made a simple Memory.h / Memory.cpp to handle memory calls. I have my Main.cpp calling a "GetProcessID" and "OpenProcess". This all works fine. However i decided to split up things across multiple cpp files.
For instance i have attached some code..
Main.cpp:
#include <Windows.h>
#include <iostream>
#include "Other.h"
#include "Memory.h"
Using namespace std;
Memory Mem;
int main(){
Mem.GetProcessID(ProcessName); // Getting Process ID
cout << "Main.cpp ProcID : " << Mem.ProcID;
TestCall();
}
In this i get the process ID I expected. In Other.h:
#include "Other.cpp"
void TestCall();
in Other.cpp:
#include "Other.h"
#include "Memory.h"
#include <windows.h>
#include <iostream>
using namespace std;
Memory Mem1;
void TestCall()
{
cout << "Other.cpp ProcID: " << Mem1.ProcID;
}
I get both couts come through on console however main displays the ProcID, Other.cpp displays 0 unless i also add:
Mem1.GetProcessID(ProcessName);
to other.cpp.
Is there a way i can "share" the process id? I also go on to getting base module address and opening a handle. these are also not "Shared". I don't really want to have to open 2 handles, 2 base address calls etc.
Things i have tried...
1) Putting this into Memory.h:
class Memory{
Public:
DWORD ProcID;
}
incase anyone is wondering... This is my memory.h and memory.cpp
Memory.h (this is in the public class)
DWORD GetProcessID(LPCTSTR ProcessName);
Memory.cpp
DWORD Memory::GetProcessID(LPCTSTR ProcessID)
{
HWND gWindow = FindWindow(NULL, ProcessID);
DWORD ProcIDBuffer;
GetWindowThreadProcessId(gWindow, &ProcIDBuffer);
return Memory::ProcID = ProcIDBuffer;
}
Thanks in advance!