CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2020
    Posts
    1

    Help in Converting Dialog MFC Application to Command Line Application

    I have a legacy application that was given to me to convert it to a console application. My only issue is that I'm fairly new to coding in C++ and need any tips/help you can provide.
    Currently the MFC application opens 2 files does a calculation and outputs a new file with the calculation in it. The GUI is only used to select which 2 files the user wants to use to do the calculation on.
    Basically I want to send arguments via the command line instead of the GUI. Is there a "quick" way of doing this where I can reuse some of the old code without starting writing a new application entirely?
    Also, any links that I can read up on would be very much appreciated!

    Thanks.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Help in Converting Dialog MFC Application to Command Line Application

    It depends on how the MFC app was written. If it was written in a manner that separated the UI from the data/logic then it should be simple to pull that code out and put it into a console app. On the other hand, if the app mixed the data/logic in woth the UI code, it will be harder to extract the non-MFC code.

    That being said you could simply add command line parameters to the MFC app and run the app as a console app if parameters are present (or as the MFC dialog app if not).

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Help in Converting Dialog MFC Application to Command Line Application

    For a console program, the main() function is the entry point to the program and must be present. It takes optional parameters from which you can extract the passed command line arguments. See https://docs.microsoft.com/en-us/cpp...s?view=vs-2019
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured