Problem with command line parameters Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bigpilot
I live to help wx-kind
I live to help wx-kind
Posts: 184
Joined: Tue Sep 19, 2006 8:33 am

Problem with command line parameters

Post by bigpilot »

I've made a text editor and I'm having problems getting it to work with the command line file being passed to it.

My code looks like this:

Code: Select all

  

        MainFrame* pMainFrame = new MainFrame( NULL );
	wxArrayString arrFilePaths;

	if ( this->argc > 1 )
	{
		for (int i = 1; i < this->argc; i++)
		{
			wxString strPath = this->argv[i];
			arrFilePaths.Add( this->argv[i] );
		}

		pMainFrame->OpenMultiple( arrFilePaths );
	}
I've set the Shell Open (MSW) command for .txt files to:
"C:\Program Files\MyApp\MyApp.exe" "%1"
and this works fine for .txt files. However, when trying to open another file with the extension .vb with my app it complained it couldn't find the files. It turned out it had inadvertently parsed the command line arguments:

C:\Document and Settings\User1\Desktop\Testfile.vb

had become three calls:

C:\Document
and
Settings\Users1\Desktop\Testfile.vb

al of which the system could not find.

How does one handle such case? Contatenate the argv arguments and then try to open until it works?
Soon to be world famous ;)
bigpilot
I live to help wx-kind
I live to help wx-kind
Posts: 184
Joined: Tue Sep 19, 2006 8:33 am

Post by bigpilot »

I solved it by contactenating the command line arguments and trying with wxFileName::FileExists() to see if the file exists. If it's valid I add it to the files to be opened.
Soon to be world famous ;)
Post Reply