473,387 Members | 1,678 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.

running in windows and from command line

I am trying to write a little program that can be run as a Windows
program or as a command line program. I'm really not sure the best way
to do this, so what I came up with so far was to check for command
line parameters (code shown below). This works, except that printf()'s
don't display anything. Is there a better way to do this?

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)!="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
Jul 19 '05 #1
7 6005
You dont need any of that windows-api stuff, just write a normal main function:

int main()
{
printf("Hello world!!\n");
return 0;
}

and you should get a command line program.

--
Gustav Svensson
gu***@matris.org
Jul 19 '05 #2
Ken Innes wrote:
I am trying to write a little program that can be run as a Windows
program or as a command line program. I'm really not sure the best way
to do this, so what I came up with so far was to check for command
line parameters (code shown below). This works, except that printf()'s
don't display anything. Is there a better way to do this?

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)!="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}


Jul 19 '05 #3
Buster Copley wrote [nothing]

Sorry. Slipped.

Jul 19 '05 #4
Ken Innes wrote:
I am trying to write a little program that can be run as a Windows
program or as a command line program. I'm really not sure the best way
to do this, so what I came up with so far was to check for command
line parameters (code shown below). This works, except that printf()'s
don't display anything. Is there a better way to do this?

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)!="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}


And again, this is OFF TOPIC here. Go to the microsoft.public.* tree for
better results.

--
Unforgiven

"Most people make generalisations"
Freek de Jonge

Jul 19 '05 #5
Gustav Svensson <gu***@matris.org> wrote in message news:<20030917234735.7301d4bf.gu***@matris.org>...
You dont need any of that windows-api stuff, just write a normal main function:

int main()
{
printf("Hello world!!\n");
return 0;
}

and you should get a command line program.


But I do need that windows-api stuff, because I want the program to
run as a Windows program with a Window-interface as well as on a
command line without a Window-interface.

Originally, I was hoping that I could just put a main() function in
there and that when run from the command line the program would
automatically call it instead of WinMain(), but that doesn't seem to
be the case.
Jul 19 '05 #6
Ken Innes wrote:

But I do need that windows-api stuff, because I want the program to
run as a Windows program with a Window-interface as well as on a
command line without a Window-interface.


I'm not aware of any way to do such a thing, but there certainly is no
way using standard C++, therefore the issue is not topical here. You
should ask on a Windows programming group. Please read the welcome message:

http://www.slack.net/~shiva/welcome.txt

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #7
On 18 Sep 2003 15:28:48 -0700, pr*******@hotmail.com (Ken Innes) wrote:
Gustav Svensson <gu***@matris.org> wrote in message news:<20030917234735.7301d4bf.gu***@matris.org>...
You dont need any of that windows-api stuff, just write a normal main function:

int main()
{
printf("Hello world!!\n");
return 0;
}

and you should get a command line program.


But I do need that windows-api stuff, because I want the program to
run as a Windows program with a Window-interface as well as on a
command line without a Window-interface.

Originally, I was hoping that I could just put a main() function in
there and that when run from the command line the program would
automatically call it instead of WinMain(), but that doesn't seem to
be the case.


First, see Kevin Goodsell's message about topicality, and please
follow that advice.

Now, a standard C++ program (for a hosted implementation) _must_ have a
'main' function. Otherwise it isn't standard. Some compilers, among
them Windows compilers, allow e.g. 'WinMain' as a non-standard
extension to the language, but note well: all compilers I'm aware of
also support standard 'main' for any kind of program.

One solution to the apparent problem is to create two different
programs, of different kinds, where e.g. one uses the other. <ot>It would
be a good idea to rename the Windows console one to [.com]; that little
trick, which has to do with the Windows command interpreter's search for
programs, was used by e.g. MS Developer Studio 6.0.</ot>

Jul 19 '05 #8

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

Similar topics

4
by: Laura P | last post by:
Hi, I wasn't sure whether this should be posted in the Java are or in a Solaris thread, so I shall post it in both. Sorry for the duplication. I am new to Solaris and am having trouble...
0
by: Tony C | last post by:
According to the help for pydoc, it can be run as a script, from the command line. "Or, at the shell command line outside of Python: Run "pydoc <name>" to show documentation on something" ...
2
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned...
1
by: Venkat | last post by:
I just installed Visual Studio.Net 2003 and that is supposed to add that asp.net 1.1 extension. I got an error message while opening ASP.NET project.Error is : "visual studio.net has...
1
by: Peter Rilling | last post by:
I have an EXE that I would like to be able to run from either the command-line or as a windows service. Is there a way that I can tell which context the program is running in? Basically, if it...
10
by: Mandy | last post by:
I have a command line tool that I would like to run from my .NET web application using System.Diagnostics.ProcessStartInfo. I run cmd.exe with this and then pass the command to run the tool as an...
3
by: ° ^F®êâK^ ° | last post by:
Blank hi there, I just want to explain my problem. There is an application which is coded by me running. It is an vb.net application having user controls windows forms and something like visual...
17
by: Csaba Gabor | last post by:
Is there a way to determine the path to the php executable (as opposed to the script. In other words, I am looking for the path to php.exe or php-win.exe) that is currently running (ie. how was...
3
by: WP | last post by:
Hello, I have a very simple script (or would you call it a batch file?) with the following content: connect to mydb2; DROP TABLE staff_employee_address; DROP TABLE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.