How to use HANDLE VARIABLE from main in other cpp files

Pages: 12
You can’t include .cpp , you only include .h - so it won’t work your way.... see where my problem is from now?

I want to link maincpp handle Hprocess and use the same hprocess in other source files. I don’t want to make a new Hprocess variable. I want to use the Hprocess variable already made and storing my handle process (main.cpp)

IM NOT CALLING A FUNCTION. IM TRYING TO DEFINE A FUNCTION BY CALLING READPROCESSMEMORY. BUT IT NEEDS THE HANDLE HPROCESS WHICH IS CREATED IN MAIN AND IT HAS STORED THE PROCESS HANDLE. I need the exact process handle from main to be used in a different cpp file.
Last edited on
I don't want to make a new [HANDLE] variable [as a parameter to a function]"

Why? What do you think will happen when you copy a void* variable?

I think that you think that copying your HANDLE variable will make a new process or something. This is not the case. (It could be the case for more-complicated C++ objects, but not a simple pointer.)

Anyway, if you want to continue down what I believe to be an unnecessary path, either use (1) the Singleton design pattern (or "anti-pattern" as some will argue), or (2) extern global variables.
Last edited on
Another alternative: use ReadProcessMemory() from Player_t::ReadPlayerInformation() to read the hProcess from main() in the local process. Use GetCurrentProcess() (https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess ) to get a HANDLE to the current process.
Topic archived. No new replies allowed.
Pages: 12