CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old October 20th, 2009, 11:30 AM
    bear_ben bear_ben is offline
    Junior Member
     
    Join Date: Oct 2009
    Posts: 1
    bear_ben is an unknown quantity at this point (<10)
    Unhappy Using GenerateConsoleCtrlEvent to exit a console app

    Hi,

    I'm new here as you can see. I'm new to C++ too which figures!

    Anyway I've got an app that I've inherited at work which is used to start up and shut down other apps on other local pcs. We've had issues with shutting down some apps cleanly so that they could then be started again without any problems.

    The method used to shut down console applications previously has been with TerminateProcess which hasn't been allowing the app to exit cleanly, hence the issues when restarting the app.

    I've been doing a lot of hunting around trying to find a better way to perform this. The other apps which we've developed have a crtl-c handler in them and this is the preferred method to exit them when there is a console window open.

    From my messing around, I've discovered I can't close a console application that's running in task manager (no console window) by using WM_CLOSE and as mentioned before, TerminateProcess has been causing issues. I've been trying to implement GenerateConsoleCtrlEvent so I can take advantage of the ctrl-c exit method but to no success. I've seen plenty of threads relating to this and they all make it sound so simple but in practice this just doesn't seem the case!

    For info, when the process is created, the process id is obtained from lpProcessInformation and the dwProcessId. I have also used the CREATE_NEW_PROCESS_GROUP flag that is specified to be used when using GenerateConsoleCtrlEvent.

    I've then passed the process id into the function as follows:

    GenerateConsoleCtrlEvent( CTRL_C_EVENT, dwPID );

    I've also tried using the SetConsoleCtrlHandler function both in the calling package and also within the console application to retieve the crtl event, but still I can't get this to work. I'm clearly doing something wrong but would really appreciate some guidance. Thanks Ben
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:57 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.