Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is it possible to restart my application from within my application?

Is it possible to restart my application from within my application?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    julych
    wrote on last edited by
    #1

    Is it possible to restart my dialog application from within or should I create an outside object to close it and then to start it again?

    P A B 3 Replies Last reply
    0
    • J julych

      Is it possible to restart my dialog application from within or should I create an outside object to close it and then to start it again?

      P Offline
      P Offline
      Peter Molnar
      wrote on last edited by
      #2

      If your application lives just in an *.exe there isn't a possibility, but if in a *.dll there is. You load your own .dll from an *.exe, when the *.dll attaches to the *.exe the reason for call in DllMain is DLL_PROCESS_ATTACH. Depending upon value of dwReason you can start your code. If your process starts, your *.exe is shown in the task manager (with the *.dll linked to it), and it can be killed from there. In this case your DllMain gets called again with reason DLL_PROCESS_DETACH. From here you have to do a ShellExecute on your *.exe, and your process with the linked *.dll starts again. Peter Molnar

      1 Reply Last reply
      0
      • J julych

        Is it possible to restart my dialog application from within or should I create an outside object to close it and then to start it again?

        A Offline
        A Offline
        Abin
        wrote on last edited by
        #3

        You basically need two exe files, say, A and B. Now you want to restart A "within" A, you simply let A do the following: 1, Launch B via a call to ::ShellExecute. 2, Terminate itself. At this point B has been launched and A has been terminated. Now, what B does are the following: 1, Wait a few seconds by using a timer. This is usually necessary because A may need some time to cleanup, i.e., de-allocate resources, clean files, whatever, etc. 2, Launch A via a call to ::ShellExecute. 3, Terminate itself. So now your A is "restarted".

        1 Reply Last reply
        0
        • J julych

          Is it possible to restart my dialog application from within or should I create an outside object to close it and then to start it again?

          B Offline
          B Offline
          Brian Shifrin
          wrote on last edited by
          #4

          Yes, few solutions awailable: 1) External executable, when given control restarts app. 2) Create batch file that restarts application with flag delete on close, execute it, and exit application. 3) Same executable, or new version of exec or exe making copy of itself, with when started with "reboot" command option, waits for executer to close, places itself into original directory, and re-starts itself. I used to use (1), now I use (3) for self-update.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups