Application and Console???


G

Guest

Is there anyway we can write an Application project and also have an option
for console where it take the command line for input?

Thanks
 
Ad

Advertisements

J

James Curran

Yes, it can be done using the AllocConsole API call (via P/Invoke). An
example can be found here:
http://www.pinvoke.net/default.aspx/kernel32/AllocConsole.html

(Note, no matter how many times I correct that page, someone insists on
restoring the older, wrong information, so, if you don't see an example on
that page, check earlier revisions)

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 
K

Kai Brinkmann [MSFT]

Sure, it's not even hard. Just create a console project (so VS creates void
main) but also have your class inherit from System.Windows.Forms.Form. In
Main, do all required command line parsing to decide whether you want to run
as an app or in a console. For example, if the EXE is started with no
arguments you might want to run as an app. Or you could have a switch
indicating wether to start the UI or not. Create an instance of your form.
You can run this as a Windows app by using:

System.Windows.Forms.Application.Run(<instance of your form>);

If you don't want to start the UI, just use the form object as you would
work with any other class.

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements

G

Guest

thanks for the info, it help a lot.

Kai Brinkmann said:
Sure, it's not even hard. Just create a console project (so VS creates void
main) but also have your class inherit from System.Windows.Forms.Form. In
Main, do all required command line parsing to decide whether you want to run
as an app or in a console. For example, if the EXE is started with no
arguments you might want to run as an app. Or you could have a switch
indicating wether to start the UI or not. Create an instance of your form.
You can run this as a Windows app by using:

System.Windows.Forms.Application.Run(<instance of your form>);

If you don't want to start the UI, just use the form object as you would
work with any other class.

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

ttan said:
Is there anyway we can write an Application project and also have an
option
for console where it take the command line for input?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Console application 2
Console Applications 8
Console Application 7
Console application 1
console applications 3
Console Application 1
Console application 1
Console Application 2

Top