Application to accept arguments while running
I am using visual studio 2008 and MFC. I accept arguments using a subclass of CCommandLineInfo and overriding ParseParam().
Now I want to pass these arguments to the applicat开发者_如何学JAVAion while running. For example "test.exe /start" and then to type in the console "test.exe /initialize" to be initialized again.
is there any way to do that?
Edit 1: Some clarifications. My program starts with "test.exe /start". I want to type "test.exe /initialize" and initialize the one and only running process (without closing/opening). And by initialize I mean to read a different XML file, to change some values of the interface and other things.
I cannot think of an easy way to accomplish what you're asking about.
However, you could develop your application to specifically receive commands, and given those commands take any actions you wanted based upon receiving them. Since you're already using MFC, you can do this rather easily. Create a Window (HWND) for your application and register it. It doesn't have to be visible (this won't necessarily make you application a GUI application). Implement a WndProc, and define specific messages that you will receive based on WM_USER + <xxx>
.
First and obvious question is why you want to have threads, instead of processes.
You may use GetCommandLine
and CommandLineToArgvW
to get the fully formatted command line. Detect the arguments, and the call CreateProcess
or ShellExecute
passing /watever to spawn the process. You may also want to use GetModuleBaseName
to get the name of your own EXE.
精彩评论