473,773 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("kern el32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kern el32.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 2450
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.co m

<ff*****@gmail. comwrote in message
news:78******** *************** ***********@i29 g2000prf.google groups.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("kern el32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kern el32.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
1324
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
2317
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 click a button on the form. Any directions, examples, etc. Thanks Sunny
3
3708
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
6344
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 complete project to show what happens. If anybody has an idea of how to fix this, please let me know. Yes I am aware that this is all in .Net 2. Thanks in advance.
2
7166
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 windows form code behind I receive the following; {"The request failed with HTTP status 401: Unauthorized."} when trying to execute this.dataGridView1.DataSource = ws.ReturnStudentDS(); not sure if it is relevant but the web.config in the...
2
4750
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); Console.WriteLine(String.Format("Sleeping...{0}", i)); } Console.WriteLine("Done!"); </code>
10
6689
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 hidden so that each key stroke generates '*' as its output, hiding the what was typed by the user. If anyone knows how to do this in C# your help would be greatly appreciated. Thanks in advanced,
5
12048
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 show star(*) when entering?
2
2071
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 seperate file so....
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.