473,387 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Exe supporting both winform and console mode

Hi

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
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kernel32.dll")]
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.

Jan 8 '08 #1
1 2439
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ff*****@gmail.comwrote in message
news:78**********************************@i29g2000 prf.googlegroups.com...
Hi

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
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kernel32.dll")]
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.

Jan 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bnaya | last post by:
I'm invoking the same Dll from Console application and WinForm application Both signed with SrongName. the class that I'm invoking is protected with StrongNameIdentityPermission Demand
5
by: Sunny | last post by:
Hi, If I have (hmm, at least I want to have :) ) a winform, displaying the progress of a long duration method, which is running in a separate thread, how do I implement canceling the thread, if I...
3
by: Liren Zhao | last post by:
I use some "Console.WriteLine(some strings here)" to display some debug information in my winform program. How can I get the information in my programe or same them in a text file ?
5
by: Publicjoe | last post by:
I am working on a little app which uses colour in the console window. I have created a class to extend the console functionality but the ClearScreen method does not work correctly. I am enclosing a...
2
by: hazz | last post by:
I don't get it. I have a VS2005 solution with a web service project and a windows project. The web service when tested on its own works fine. But when I add it as a web reference and refer to it my...
2
by: Steve | last post by:
I have created a console app that simply prints out a message a couple times, then exits, here is the code: <code> for(int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(500);...
10
by: ryan.andrus | last post by:
Hi, I need to make a command line application that I have written support an option that allows the user to use the /p:* switch to specify that they would like to type a password but have it...
5
by: Hooyoo | last post by:
Hi, here. I write following codes: string password = Console.ReadLine(); I want users enter their passwords, but readline will show content of password when entering, so is there any way to...
2
by: CSharper | last post by:
I have written a winform application not I need to run the same app in colsole mode without user interaction. Is there an easy way to do this? I have all the information available as input in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.