LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

handling filename with spaces from windows command line

Windows XP Pro
CVI 5.5
 
Howdy,
I have two separate apps, we'll call them MDS and ASN.   They each have associated file extensions .mds and .asn, respectively, in Windows.  They are in no way associated with each other - they are independent programs.
 
When you double click on a .mds file the MDS program starts up and loads the file fine.  It sees the filename passed in from the command line in 8.3 format (i.e.C:\DOCUME~1\user\Desktop\TESTFI~1.MDS).  Thus, argv[2] is the whole pathname for the file that was double clicked.  This is great because if a file has some goofy filename with multiple spaces in a row it will still be opened because it's still a single string in argv.
 
Here's the rub, application ASN has the same code to handle the command line args passed from Windows.  However, it receives the filename in the long format.  If the filename has single spaces and/or long strings of spaces then the filename is broken up into individual strings like each space in the filename actually separated a command argument (i.e. argv[2] = "C:\DOCUMENTS"  argv[3] = "and"  argv[4] = "Settings\user\Desktop\TEST"   argv[5] = "FILE.MDS").  There is no way to recover the multiple spaces from this (that I know of).
 
Neither program is a 16-bit application.  (But Windows would pass 8.3 format filenames to a 16-bit app)
 
My questions are:
1) Why does MDS receive 8.3 format filenames from Windows when a mds file is double clicked?
2) How can I get Windows to pass 8.3 format filenames to ASN?
 
3) Alternatively, is there a way to find the file that activated the application other than via the command line (like some call from the windows SDK)?
 
Thanks for reading my post!
-shrew
0 Kudos
Message 1 of 2
(3,302 Views)
A few suggestions:
 
If you view your file associations in explorer, you can see exactly how the string will be passed to the application.
 
Open an instance of explorer and go to Tools->Folder Options->File Types and find the file type in question.
 
Click 'Advanced'.
 
Select the default open action and click 'Edit...'.
 
You will see (in Application used to perform action) that it has your application path followed by something like "%1".
 
Make sure that this string has quotes around the %1 ("%1", not just %1); this will cause it to be considered a 'single' argv argument instead of multiple space-separated ones.
 
 
Another option would be to use WinMain instead of main; the prototype for WinMain is like this:
 
int WinMain(      
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
);
 
Using this, lpCmdLine will be the exact command line used to launch the program and will not be broken up as it is using main/argv.
 
 
Hope this helps,
 
-alex

Message Edited by Alex D on 03-07-2006 05:07 PM

0 Kudos
Message 2 of 2
(3,286 Views)