Answer the question
In order to leave comments, you need to log in
C++ How to open a file in an external application and be sure to get the process ID?
It is necessary from an application written in C ++ to be able to open files in external applications, get the process ID and track its closing. As soon as the file is closed, perform some action.
Where to dig?
Answer the question
In order to leave comments, you need to log in
In the sense you need to take notepad and open a file with it, then track the closing of notepad?
Such a mechanism will not work, for example, with notepad ++, if its process is already running, the created process will give data to the already running one and exit successfully.
The process ID can be obtained using CreateProcess, but I described the big pitfall above. A more or less sane option was voiced by Ramires, but again he will stumble upon a problem with notepad ++, it seems like it could be tracked by the process name, but not all applications work this way.
On Windows, I can suggest ShellExecuteEx, which opens the file in the application by default and returns hProcess. On hProcess it is possible to wait for closing of application. But if you need to track not the closing of the application, but the closing of the file, then you can try to open the file exclusively in a loop with some Sleep until you get success.
There is also ReadDirectoryChangesW, but in my opinion it does not notify about the release of the file descriptor.
Another point: there are applications that do not keep files open, for example, if you open a text file with notepad, then notepad reads the file into memory and immediately closes it, that is, it does not keep the handle.
As I understand it, there is no way to influence an external application, you need to somehow track the fact that the file is closed after we have launched this application and fed our file to it.
There was only one idea - to parse the output of Handle v3.5 By Mark Russinovich (taken from here ).
C Windows worked a little, I hope, someone will prompt something more graceful.
If it's enough for you to determine the very fact that the file has been modified,
then on windows look in the direction of "hang a hook to change the file"
here are the links to start
how-do-i-make-my-program-watch-for-file-modification-in -c
Obtaining Directory Change Notifications
AxisPod does this thing keep track of file/directory changes? Or is it still waiting to close?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question