Exe supporting both winform and console mode




I would like to implement a single exe which could be invoked either
as a standard windows form (no argument) or as a console app (when run
with app.exe -nologo).

I tried compiling the exe as a winform app and use win32 app to create
a console but when launched from a dos command line, it does not use
the launching console but create a new one
public static extern Boolean AllocConsole();
public static extern Boolean FreeConsole();

I also try compiling directly as command line app but in that case the
console stay in the background when launched as a standard window app.

Thanks in advance for any help.



Nicholas Paldino [.NET/C# MVP]

You can't. What you should do is factor out your logic into a separate
assembly, which has no UI in it. Then, you can create two separate
assemblies which create the appropriate ui (console or winforms) and access
the logic in the shared assembly.

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