Event handling

I know c++ doesn't have event handling so I was wondering is it possible to make a program that alerts you when another program is started like skype or something.
That would be an alert from the Operating System, not a language like C++.

If you are talking about Windows, then I know kernel mode code can get notifications, but not user mode code. This means a driver could get notified, but not a regular application. You must therefore program a driver for this particular application.

I know nothing about Mac OS or *nix.
Is it possible to check what processes are running and look up for that one we need.
Yes, use the EnumProcesses() or CreateToolhelp32Snapshot() functions in Windows.
C++ is only concerned with manipulating the program itself. It cannot assume that it's run on an operating system that allows multiple programs to run simultaniously.
If you want to this program to work with other programs, you'll need an interface to the operating system.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class event
{
       thread* threads;
       int n;
       public:
       event(): n(0), threads(new thread[0]){}
       event(const event&)=delete;
       event(event&&)=default;
       template<typename Func, typename... Args>
       event(bool (*cond)(), Func f, Args... args): threads(new thread[1])
       {
              threads[0]=thread([&](){while (true) if (cond()) func(args...});
              n++;
       }
       template<typename Func, typename... Args>
       event& operator+=(bool (*cond)(), Func f, Args... args)
       {
              threads=new(threads) thread[n+1];
              threads[n]=thread([&](){while (true) if (cond()) func(args...});
              n++;
       }
};

I didn't test it, but im pretty sure it should work.
What's the point of spinning? You need a way to wait until the event is signaled. And that means using the sync facilities of the underlying OS.
Topic archived. No new replies allowed.