473,568 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(HINSTAN CE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)! ="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize() ;
Application->CreateForm(__c lassid(TForm1), &Form1);
Application->Run();
}
Jul 19 '05 #1
7 6022
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.or g
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(HINSTAN CE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)! ="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize() ;
Application->CreateForm(__c lassid(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(HINSTAN CE, HINSTANCE, LPSTR, int pszCmdLine)
{
if(ParamStr(5)! ="") {
main1(); //command line mode
return(0);
}
try
{
Application->Initialize() ;
Application->CreateForm(__c lassid(TForm1), &Form1);
Application->Run();
}


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

--
Unforgiven

"Most people make generalisations "
Freek de Jonge

Jul 19 '05 #5
Gustav Svensson <gu***@matris.o rg> wrote in message news:<200309172 34735.7301d4bf. gu***@matris.or g>...
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*******@hotma il.com (Ken Innes) wrote:
Gustav Svensson <gu***@matris.o rg> wrote in message news:<200309172 34735.7301d4bf. gu***@matris.or g>...
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
automaticall y 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
12061
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 running a long Java command from a shell script. Firstly, my Solaris (8) / Java setup. Mu machine already had Java 1.2
0
2021
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" However, when I run pydoc from the Windows XP command line, it launches my editor (Codewright) and displays pydoc.py in the editor. I want to be...
2
6646
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 to the DOS prompt. I just started learning Python a couple of weeks ago, so please bear with me. I have a script that(for now) uses command line...
1
1882
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 detected that the specified web server is not running ASP.net version 1.1. You will be
1
5540
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 runs as a service, I would want it to call ServiceBase.Run (which will then call the execution logic). If it is run at the command-line, I simply...
10
3808
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 argument to the process. When I try this from a Windows application it works fine, however, when I do this from my web application I get errors. ...
3
1610
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 components. Also i can send some command line options from the command line for example >> C:\xxx.exe -a
17
2626
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 this script called) on Windows (I'm on Win XP Pro)? WScript/CScript (when programming in VBScript) allow this, for example. Failing that, is there...
3
3686
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 staff_employee_address_telephone; DROP TABLE staff_employee; DROP TABLE staff; commit; terminate;
0
7605
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...
1
7665
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...
0
6277
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...
1
5501
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...
0
5217
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...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.