You are doing it wrong. If you think about it, you will understand that when responding to menu events using your custom "actions", you need some code to run during the targeting process. This means that you will need to enter the code into another process in order to achieve what you want.
Since you still have to enter the code, I strongly recommend that you take a look at the DLL injection into another process (search for โDll Injection Exampleโ). This will load your code into another process, and you can create your own menu there.
It also has the advantage that a foreign application will not rely on the responsiveness of your application - everything will be in the process.
source share