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

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


command line arguments

Lee Thompson -- lee@usa.nai.net
Monday, May 27, 1996

Hi,

Enviro:  VC 4.1 and Win95

It seems this must be a common problem, but without MSDN I am having a 
hard time finding an answer.  When I double-click on a file with an 
extension associated with my program, I get a truncated pathname if 
there is a space in either the path or the file name.  WinMain gets 
lpCmdLine correctly, but in ParseCommandLine, the cmdInfo structure is 
filled in with the path and filename truncated at the first space 
encountered.

Hopefully someone can point me to a KB article or work-around for this. 
If so I will then thank them.

Lee Thompson



Alberto Massari -- alby@belva.laboratorium.dist.unige.it
Friday, May 31, 1996

[Mini-digest: 7 responses, though some missed the point about the
fact that this was about using Explorer, not a DOS prompt.]

At 11.59 27/05/96 -0400, you wrote:
>Hi,
>
>Enviro:  VC 4.1 and Win95
>
>It seems this must be a common problem, but without MSDN I am having a 
>hard time finding an answer.  When I double-click on a file with an 
>extension associated with my program, I get a truncated pathname if 
>there is a space in either the path or the file name.  WinMain gets 
>lpCmdLine correctly, but in ParseCommandLine, the cmdInfo structure is 
>filled in with the path and filename truncated at the first space 
>encountered.

Your command line should have been enclosed in '"'. The same problem appears
with program like Microsoft Word and Visual C++ IDE, so I think it's a bug
of Explorer....

        Alberto
----------------------------
    |\      _,,,--,,_
    /,`.-'`'   ._  \-;;,_
   |,4-  ) )_   .;.(  `'-'
  '---''(_/._)-'(_\_)    
------------------------------------------------------------------
Alby@MusArt.dist.unige.it is: 	Alberto Massari

Laboratorio di Informatica Musicale
D.I.S.T. Dipartimento di Informatica, Sistemistica e Telematica
Universita' di Genova
Via all'Opera Pia 13,
I - 16145 Genova ITALIA		http://MusArt.dist.unige.it/~alby/
------------------------------------------------------------------

-----From: kitk@mudshark.sunquest.com (Kit Kauffmann)

I prefer using the old-style arguments via:

extern "C"
{
extern  int     __argc;
extern  char    **__argv;
}

I'm still using 16-bit - I assume the 32-bit system still provides them?

HTH!
Kit
My plants don't trust me any more.

-----From: Dave Kolb 

Change the registry entry for your filetype to put quotes around the %
filespec argument.

Dave Kolb

Dave Kolb                     Compuserve: 72410,407@compuserve.com
SAS Institute, Inc.           EMAIL:      sasdxk@unx.sas.com
SAS Campus Drive - R3282      Phone:      (919) 677-8000 x6827
Cary, NC  27513-2414 USA      FAX:        (919) 677-8123

-----From: beriksen@cda.com

     I haven't tested this, but, in '95 and NT I believe that you should 
     pass command-line parameter strings in double quotes.  (e.g., if I am 
     at a dos prompt and I'm in c:\, and I have a directory called 
     c:\My Directory then I have to type cd "My Directory" to get to My 
     Directory.  Leaving off the quotes produces an error.)
     
     Brian Eriksen
     CDA/Wiesenberger
     beriksen@cda.com

-----From: Neal Stublen 

Have you entered the registry association correctly?  I believe the
"...\shell\open\command" key should follow the format:

	"appname.exe" "%1"

Placing the double quotes around the %1 parameter mean that everything
in the double quotes should be considered as the first parameter. 
Otherwise, the first parameter is delimited by a space, which is causing
your truncation.

-----From: "Greg Tighe" 

Actually, this is a fairly common problem with applications 
needing to support long file names - even Microsoft Word gets tripped 
up by this one.

Solution:  Go into Windows Explorer.  Under the View menu, select 
Options.  Click on the File Types tab and find the description of 
your document type.  Select that file type and click the Edit button.

Under the Actions list box, select 'open'.  Click on the Edit button.
You should see something like this under 'Application used to perform 
action':

	"C:\PROGRA~1\MYAPP\myapp.exe" %1

You need to put quotes around the argument passed to your program so 
that Windows will pass it in as a single argument and not as a series 
of space-delimited arguments:

	"C:\PROGRA~1\MYAPP\myapp.exe" "%1"

Beware, though - you may need to parse out the leading and trailing 
double quote characters, much as CDocManager::OpenDocumentFile() 
does.

I believe under Windows95 the quotes may be parsed out before the 
argument is passed to your app, but under WinNT they aren't.

Hope this helps.


	-Greg Tighe
	Applied Intelligent Systems, Inc.
	Ann Arbor, MI
	gdt@aisinc.com
-----From: "David W. Gillett" 

  The command-line parse expects spaces to delimit tokens.  To 
specify a token with an embedded space, put quotes around the entire 
token -- they'll be stripped off, but it will get parsed properly.

> Hopefully someone can point me to a KB article or work-around for
> this. If so I will then thank them.

  I don't know of a KB article, but the problem arises not only as a 
development issue but also as an end-user issue when configuring 
command lines, such as registry entries for file types.

Dave

 




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