0

Is it possible to convert a dialog based MFC application into a command line application in vc++/c++/mfc?

a) There are some event handlers on UI like a button click on "connect" button would establish a connection, similarly would want to establish a connection when connect command is passed as an argument to mfc application exe(Aim is to do the same task but with a command line argument Ex:on Cmd line C:\Users\desaira>MFCApplication.exe connect)

b) a button click event on UI does disconnecting the connection currently; similarly would want to disconnect a connection when disconnect command is passed as an argument to mfc application exe (Aim is to do the same task but with a command line argument Ex:on Cmd line C:\Users\desaira>MFCApplication.exe disconnect)

c) Similarly execute command should be executing a file given to it

Please post how can i design this requirement. Is it doable or not with minimal changes i.e. a new console application talking to mfc application and simulating all the UI actions with arguments to command Ex: C:\Users\desaira>MfcApplication.exe connect connectionSettings

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Ravi
  • 1
  • 1
    Yes it is possible. Move the funcitons connected to the MFC buttons to a console application and call them from main. You wouldn't need to pass disconnect as a command line argument because that's implying the application isn't already running. In which case, it was never connected..Since the UI typically runs in its own thread if you want to add a disconnect then you might want to create a separate thread for looping user input. – Irelia Oct 01 '19 at 13:19
  • 1
    *There are some event handlers on UI like a button click on "connect" button would establish a connection* -- You shouldn't have initially designed your application this way, where you hard-code business logic in UI controls. What if you change the control? Or not use a UI at all? The logic should be within functions and/or objects that do not need to know who or what is the caller. Separation of concerns, MVC model, whatever you want to call it, that's the pattern that would have been a better choice. – PaulMcKenzie Oct 01 '19 at 13:28
  • Are you sure you want it re-running the console application on EVERY UI event? Would you then need to store the current state of the console application in a state file of some kind? Are there any non-UI events (e.g. WM_TIMER) that you also need to respond to? The model you may be looking for is a service type application that can run without a user login, but then have a UI app that interfaces to this service to get status and/or issue requests to the service? – franji1 Oct 03 '19 at 03:48
  • The requirement is actually running a mfc application through command line, Ex: C:/Users>MH.exe. The point is the instance of application has to be persistent , so that the application has to wait on to recieve further commands For Ex: 1)launch a exe which starts an instance and wait on i/p from the user, lets say I want to use futher commands like "Execute", "Stop Execute", "Disconnect", "IsActive"; the instance should vanish returning the control to CLI upon clicking on something like esc or ctrl+c. Is this possible to achieve with minimal modifications? – Ravi Oct 14 '19 at 05:29
  • instance of application has to be persistent , so that the application has to wait on to receive further commands on single instance run For Ex:1)launch an exe which starts an instance and wait on i/p from the user,lets say I want to use further commands like "Execute", "Stop Execute", "Disconnect", "IsActive"; the instance should vanish returning the control to CLI upon clicking on something like esc or ctrl+c, until that it has to use the same instance. how to make a instance persistent on command line , so that it waits on to receive further cmd's from user? @PaulMcKenzie – Ravi Oct 14 '19 at 06:52

0 Answers0