views:

94

answers:

1

im somewhat new to c++ so i don't know how to do this but my main point in recoding this is to incress the speed of my program, i have been coding a project and my code is:

HWND hWnd = FindWindow(NULL, L"*window's name*");
DWORD th32ProcId;
HANDLE hProc;

GetWindowThreadProcessId(hWnd, &th32ProcId);

hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, th32ProcId);

so i have about 20 functions that all use that at the start of each time i run them and the value will never change so is there some way i can declare and then set it at the value of what it finds?

my code is set up like this

one main file int main() and it's just set on a loop and it keeps retesting and calls the other functions and everything else is in a void name() and i have 2 int name()

im using VC++ 2008.

edit no :| i just want a way i can share thoses values with all of the program.

+2  A: 

If I understand your question correctly you want to implement some kind of caching. That would be fine and you can create a cahe with an std::map.

You would probably have something like:

std::map<std::string, HANDLE> cacheMap;

You can then check the cacheMap to see if a result exists. It if does exist you don't need to call the function, if it does not exist you would then call the function and add the result to your map.

Brian R. Bondy
:| no not really what i wanted ty anyway
blood
I would not recommend to share handles across different programs.
Brian R. Bondy