winapi - RegisterApplicationRestart with different path -
i have 2 applications. both of them use same resources. lets call these resources "profile resources". application b cannot started until application shutsdown. have app running , trying shut down, launch app b path. explored registerapplicationrestart not accomplish it. possible done? i'm getting stuck @ point application shutdown, cant run code launch app b.
a can launch b using createprocess() before exiting, passing own process handle b. before b accesses resource, can wait on a's handle using waitforsingleobject() or related function. when handle signaled, a has terminated, b can close handle using closehandle() , move on needed.
to pass a's process handle b, a can either:
open own process handle using
openprocess()getcurrentprocessid()process id, mark handle inheritable usingsethandleinformation(), , pass handle valuebcommand-line parameter, settingbinherithandlesparameter ofcreateprocess()true.run
bfirst , have create ipc listener (named pipe, mailslot, socket, etc),acan duplicate own process handleb's use viaduplicatehandle()getcurrentprocess()source handle ,b's process handle (fromcreateprocess()) target process, send duplicate handle valuebvia ipc.
a simpler technique have a pass own process id, rather process handle, b command-line parameter, b can use openprocess() open a's process handle. although work, have small race condition - before b has chance open process handle, a might terminate , os reuse process id new unrelated process, b handle to, , wait on, wrong process.
Comments
Post a Comment