I'm making a program that compresses text files using the LZW compression algorithm and creates a seperate compressed file. I made a file type and extension and icon for this file type (.nct), and set up 2 actions for it - one that calls the program and passes the .nct file path name, uncompresses the file and displays the text in the executable window (default), and one that recreates the original .txt file (simply passes a "/c" before the .nct file path name, only accessed by right clicking the .nct). I haven't even started with the program, I'm just experimenting with the file type and argument stuff. When I drag the .nct (not a real file, just a short text file with the extension changed to nct) onto a shortcut to the program (for now it just tells me the number of arguments passed to the program (the first main() argument) and the arguments themselves (the second argument to main(), an array of pointers to char arrays)), it gives me 2 arguments - the executable path and the nct path, as I would expect. (It shows '-' at the beginning and end of the strings, so I could verify there were no spaces at the end.)


nNumberofArgs = 2
The arguments are:
0-C:\Program Files\Text Compress\TextCompress.exe-
1-C:\Documents and Settings\Nick\Desktop\hioo.nct-
That's it
Press any key to continue . . .

But when I double click the nct or right click and select open (same thing, as I made my open action default) I get 4 arguments. The first one works (it has 2 spaces in it), but it gets rid of the 2 spaces in the nct path and counts it as 3 seperate arguments.


nNumberofArgs = 4
The arguments are:
0-C:\Program Files\Text Compress\TextCompress.exe-
That's it
Press any key to continue . . .

Why? How do I fix it so that I get one argument passed as the nct path when I use the open action, instead of just when I drag it onto the executable (or call in a DOS prompt)?

When I use the create text file action, I get the /c, but I still get seperate arguments from spaces in the nct path.


nNumberofArgs = 5
The arguments are:
0-C:\Program Files\Text Compress\TextCompress.exe-
That's it
Press any key to continue . . .

Here's my appliction for Open:
"C:\Program Files\Text Compress\TextCompress.exe" %1
and here's for Convert To .txt:
"C:\Program Files\Text Compress\TextCompress.exe" /c %1

It works now... wow

I just assumed that would make it send a literal "%1", like it sends /c. I feel like an idiot now, I knew that % was just the escape sequence... After all, that's how it works everywhere else. ("\n" doesnt mean \n, it means newline, even though it's in quotes. *slaps forehead*) I was going off of what I saw other file types do, like notepad. It has
but now that I think about it, that doesn't need to have quotes around the executable path either... hmm... and I knew mine didn't work without those.


I still wonder why that caused that though....

the parser for the command line seperates
arguments by looking for whitespaces. so if
the command line parameters do not have
whitespaces in them thins work fine.
putting quotes indicates that everything
inside the quotes, including white spaces
are part of the single arg.
since argv[0] is the full path to the
executing program, it is not picked up
from the command line.
notepad.exe (and most microsoft programs)
use the win32api GetCommandLine function.
this gives the entire command line as a single
string which is then parsed as required by the

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.