Hi, I've been using cplusplus forums for a while now to help me with my codding that I'm learning and I figured I may as well make an account and ask some questions of my own so here it goes.
Is there a way too monitor an application, and to read when an event is triggered? For example:
I have a loop in an application that has x increment every time the loop occurs. Can I have another application constantly reading the first application and trigger a message or what have you when x is equal to a particular number?
Not without the app with the loop giving a bit of help. The C++ source code can be translated in a variety of ways, so there's nothing standard to hook into.
Depending on the OS, there are a number of ways one program can communicate with another.
I don't think that core c++ has any mechanism for event handler. This is a feature in an upper level like GUI (I guess you are using one).
In this sense when you use events you enter a special loop where the program you are running are expecting for user interaction. Anyway there is a whole philosophy about events so you must be more specific.
So what GUI do you intend to use? The solution may be platform dependent but it's not pure c++.
Typical execution of a program just process commands so there is no sense of event. You can use loops but there is no other function running besides the one using the loop. I mean you can expect user input from console but this is not an event exactly. The program halts waiting for this input and then resumes.
The short answer would be NO, because memory from one process is isolated so no other process can read or write to it. This is called memory virtualizaiton and you can learn about it by searching the term "virtual address space".
Having said that, ANYTHING can be done provided enough time and effort, especially if you are coding BOTH applications. You may want to read about Interprocess Communication and synchronization objects.
BTW, if my answer is to Windows-biased, it is because I only program for Windows. If your OS is not Windows, you might want to get a second opinion.
Thank you all for your responses! From the sounds of it I'm still not at the level where I couldn't be messing with this. It was more out of curiosity then anything else. I ask because I remember a program called honorbuddy that 'read' information from a game and took actions based on that information. I was curious as too how they went about doing such a thing.
I'll google around the terms you put up and learn some more.
you can always use a file to hold the info so when a value is over a number (or any other variable, im using a number value as an example) reaches a limit, it will run the desired function.
thought process:
1st program
while{
-do your function for whatever you want;
- adds value into file;
return 0;}
2nd program
-opens file from 1st program;
while{
- check value file until it reaches a certain value;
- i would use a wait statement, remember to define it urself and not use call upon the system version of wait;
- do function until it is the value you want;}
do function you wanted;
return 0;}
you will need to include <fstream> and know how to use files, it is not hard. http://www.cplusplus.com/doc/tutorial/files/
that url will help if you need to learn how to use files.