15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Program crashes when run with arguments

Alexander Stigsen -- axxion@ibm.net
Sunday, January 26, 1997

Environment: VC++ 4.0, Win 95

I am currently trying to add command line arguments to my program.

As long as I'm working within the IDE there is no problem. I can set a
filename as argument in the Build settings, run the program and it 
opens the file without problems. This works both for the Debug and
the Release version.

The problem arises when I try to run the program from outside the IDE.
If I try to pass arguments to it in any other way than from the dos promt
(doubleclicking a datafile, dragging the file icon over it...) it exits
with abnormal program termination.
As far as I can see debugging from there it happens before it even
gets to InitInstance() and as I can't recreate it from inside the IDE I
can't find the problem.

I have tried adding EnableShellOpen(), ParseCommandLine() and
ProcessShellCommand() to my programs InitInstance(). All to no avail.

Is there anything I have forgotten to include or what can the reason
be?

Thanks,
	Alexander




IGNACIO NICOLAS RODRIGUEZ -- irodriguez@envirolink.org
Monday, January 27, 1997

(In case you expect a certain order for the parameters.)
Remember the operating system sends as first parameter for an application,
the name of the application.
If it was "Nacho.exe" and I run it "Nacho -s /p", it would get:
argc = 3
argv[0] = "Nacho.exe"
argv[1] = "-s"
argv[2] = "/p"

On the other hand, if you set command options from the IDE, the programme
is not automatically passed the executable file name.




Mike Blaszczak -- mikeblas@nwlink.com
Tuesday, January 28, 1997

At 15:41 1/27/97 -0000, Ignacio Nicol=E1s Rodr=EDguez wrote:

>On the other hand, if you set command options from the IDE, the programme
>is not automatically passed the executable file name.

Really?  In what version of Visual C++ do you note that behaviour?  I've
never known it to be true, and can't reproduce it with 4.2 or 4.1.


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.




Ehab Bassilli -- ehab@total.net
Thursday, January 30, 1997

[Mini-digest: 3 responses]

If you are running Windows 95, and using the Resource Editor (perhaps u r
painting an icon or something?) -
AND THE PROGRAM CRASHES... then the problem lies with your VIDEO CARD.=20

I bet you must be using a 1 MB $30 Video Card.. Or your card needs to be
changed.=20

If that was your problem.. this would be your answer.

If not, I am sorry, and have a nice day!

Ehab Bassilli


At 09:31 PM 1/28/97 -0800, you wrote:
>At 15:41 1/27/97 -0000, Ignacio Nicol=E1s Rodr=EDguez wrote:
>
>>On the other hand, if you set command options from the IDE, the programme
>>is not automatically passed the executable file name.
>
>Really?  In what version of Visual C++ do you note that behaviour?  I've
>never known it to be true, and can't reproduce it with 4.2 or 4.1.
>
>
>.B ekiM
>http://www.nwlink.com/~mikeblas/
>These words are my own. I do not speak on behalf of Microsoft.
>           This performance was not lip-synched.
>
>
>
-----From: Dave Kolb 


If this is true (I'm presuming it is but have not tried this) then
should the IDE be fixed to add the program name or can the executed
program somehow tell the difference and adjust the arg index
appropritely. E.G. the arguments could be a list of .exe names and how
would the executed program know whether to count the first .exe name as
it's own or not?=20

Dave Kolb

>-----Original Message-----
>From:	Ignacio Nicol=E1s Rodr=EDguez [SMTP:irodriguez@envirolink.org]
>Sent:	Monday, January 27, 1997 10:42 AM
>To:	mfc-l@netcom.com
>Subject:	Re: Program crashes when run with arguments
>
>(In case you expect a certain order for the parameters.)
>Remember the operating system sends as first parameter for an =
application,
>the name of the application.
>If it was "Nacho.exe" and I run it "Nacho -s /p", it would get:
>argc =3D 3
>argv[0] =3D "Nacho.exe"
>argv[1] =3D "-s"
>argv[2] =3D "/p"
>
>On the other hand, if you set command options from the IDE, the =
programme
>is not automatically passed the executable file name.
>
-----From: Alexander Stigsen 

At 15:41 1/27/97 -0000, you wrote:
>(In case you expect a certain order for the parameters.)
>Remember the operating system sends as first parameter for an application,
>the name of the application.

Well, the problem is that I never get a chance to do any parsing. The
program exits with 'Abnormal Program Termination' before InitInstance()
ever gets called.





Mike Blaszczak -- mikeblas@nwlink.com
Saturday, February 01, 1997

At 10:18 1/30/97 -0500, Ehab Bassilli wrote:

>If you are running Windows 95, and using the Resource Editor (perhaps u r
>painting an icon or something?) -
>AND THE PROGRAM CRASHES... then the problem lies with your VIDEO CARD. 

Nobody here mentioned using the Resource Editor at all, not to mention
editing an icon ("or something").

Let's please keep the snake oil and stabs in the dark to a minimum: people
are confused enough without hearing the wrong answers and blind guesses,
don't you think?

>-----From: Dave Kolb 

>>On the other hand, if you set command options from the IDE, the programme
>>is not automatically passed the executable file name.

>If this is true (I'm presuming it is but have not tried this) then
>should the IDE be fixed to add the program name or can the executed

It's not true.  As far as I'm concerned, it's pure hogwash, in fact.
As I mentioned in a previous note, it's demonstratable that you can't
reproduce the problem using just the simplest of applications in either
Visual C++ 4.1 or Visual C++ 4.2.

Maybe it's something that happened in VC++ 1.5, but I seriously doubt
that, too.  Since the original author of that assertion hasn't responded
with more details, I think we're safe to assume that the assertion is
misinformation at best.

There's no need to pursue a workaround for a problem that doesn't exist.
I'm saddended to see irresponsible suggestions that cause people who
have a problem to chase their tails.

Prove it to yourself!  Just add 

	AfxMessageBox(__argv[0]);

to the InitInstance() of the applications that you work on today.  What
do you see when you run the app from the shell?  What do you see when
you run it from the debugger?

>-----From: Alexander Stigsen 
>Well, the problem is that I never get a chance to do any parsing. The
>program exits with 'Abnormal Program Termination' before InitInstance()
>ever gets called.

Perhaps, then, you should place a breakpoint on WinMain() or AfxWinMain()
or even in WinMainCRTStartup(). Certainly, one of these is going to be
hit.  Then, you can look at the raw lpszCommandLine parameter that
the CRT got when it was initializing or that MFC got when it was loaded.

That is to say, rather than pursuing some snake-oil remedy, I think
it would be a great idea to drop a couple of breakpoints and trace
through some code.  The debugger is a really swell tool!

A great many things happen before your InitInstance() is called, and
apparently one of them is getting sick.


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.





| Вернуться в корень Архива |