(Visual C++) aplikacja zewnetrzna z argumentami

0

witam,
mam pewien irytujacy problem, wczesniej wszystko chodzilo poprawnie, ale od kilku dni niestety nie.

Koncze pewna aplikacje i zbudowalem do niej GUI w Visual C++, z poziomu GUI wysylam parametry dla aplikacji (coder.exe). Zaznacze, ze z poziomu konsoli parametry sa czytane bezproblemowo.

Uproszczona wersja GUI:
W GUI mam 2 PolaTextowe (ze sciezka do zapisu i odczytu). Jezeli w te pola wpisze samodzielnie adres do pliku wsystko dziala poprawnie. Jezeli robie to przez openDialogsBox wywala mi blad, ale po kompilacji:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Additional information: Das System kann die angegebene Datei nicht finden

( to z niemieckiego: System nie moze znalezc wskazanych Danych)

Wysylane argumenty sa za kazdym razem identyczne, etc. Myslalem, ze moze jakis blad sie pojawiac podczas kilkukrotnego uruchamiania aplikacji, ale tez nie. Mysle, ze cos moze byc z DialogsBoxem.
Ogolne dzialanie Programu przez DialogsBox:

  1. wskazanie Pliku otwarcia, wpis to TextBoxa,
  2. generowanie pliku do zapisu (zawsze pelna sciezka)
  3. pobranie sciezek z TextBoxow (dla zapisu i odczytu)
  4. wysylanie obu sciezek dostepu jako argument: pathIn+" "+pathOut

Gdzie moze lezec problem ?? Dziekuje za pomoc.

Tu jeszcze umieszczam wycinek omawianego kodu:

private: System::Void BTN_Open_Click(System::Object^  /*sender*/, System::EventArgs^  /*e*/) {
					Stream^ myStream2;
					OpenFileDialog^ openFileDialogs = gcnew OpenFileDialog;
					openFileDialogs->InitialDirectory = "c:\\";
					openFileDialogs->Filter = "NET files (*.NET)|*.NET|xml Files (*.xml)|*.xml|All files (*.*)|*.*";
					openFileDialogs->FilterIndex = 3;
					openFileDialogs->RestoreDirectory = false;

					if ( openFileDialogs->ShowDialog() == System::Windows::Forms::DialogResult::OK )
				 {
					 if ( (myStream2= openFileDialogs->OpenFile()) != nullptr )
					 {
            // Insert code to read the stream here.
			
				fullInPath=openFileDialogs->FileName;//c:\\test.net
				fileInType=fullInPath->Substring(fullInPath->Length-3,3);//net
				pathIn=fullInPath->Substring(0,fullInPath->Length-3);//c:\\test.
				pathOut=fullInPath->Substring(0,fullInPath->Length-3);//c:\\test.
				if ((fileInType=="NET")||(fileInType=="net"))
				{
					RB_Koder->Checked=true;
					fileOutType="xml";
				}
				else if ((fileInType=="xml")||(fileInType=="XML"))
				{
					RB_Dekoder->Checked=true;
					fileOutType="NET";
				}
				fullOutPath=pathIn+fileOutType;
				TB_pathOut->Text=fullOutPath;
				TB_pathIn->Text=fullInPath;//"C:\test.NET"

				//TB_pathOut->Text="C:\\test.xml";
				//TB_pathIn->Text="C:\\test.net";
            myStream2->Close();
         }
      }

				}
private: System::Void BTN_Run_Click(System::Object^  /*sender*/, System::EventArgs^  /*e*/) {
					if ((RB_Koder->Checked==true)||(RB_Dekoder->Checked==true))
					{
						if ((RB_Koder->Checked==true)&&(RB_Dekoder->Checked==false))
						{
							Process::Start("..\\Release\\koder3.exe" ,TB_pathIn->Text+" "+TB_pathOut->Text);
						}
						else if((RB_Koder->Checked==false)&&(RB_Dekoder->Checked==true))
						{
							fullOutPath=TB_pathOut->Text+TB_fileOut->Text;
							Process::Start("..\\Release\\dekoder1.exe");
						}
					}
					else MessageBox::Show("Choose koder/dekoder");
					
					//BTN_Results->Enabled=true;
				}

Zauwaz, ze po uruchomieniu funkcji Open_Clic, psuje sie odczyt z pol TB_pathIn(out), bez klikania, nawet z poczatkowymi wartosciami ->Text, wszystko dziala....

0

okay, juz dziala :), funkcje tak oto zmienilem:

private: System::Void BTN_Open_Click(System::Object^  /*sender*/, System::EventArgs^  /*e*/) 
					{
					Stream^ myStream;
					OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
					openFileDialog1->InitialDirectory = "c:\\";
					openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
					openFileDialog1->FilterIndex = 2;
					openFileDialog1->RestoreDirectory = true;

					if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
					{
					if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
					{
					fullInPath=openFileDialog1->FileName;
					fileOutType="xml";
					if ((fullInPath->Substring(fullInPath->Length-3,3)=="NET")||(fullInPath->Substring(fullInPath->Length-3,3)=="net"))
					{
						fileOutType="xml";
						RB_Koder->Checked=true;
						RB_Dekoder->Checked=false;
					}
					else if ((fullInPath->Substring(fullInPath->Length-3,3)=="xml")||(fullInPath->Substring(fullInPath->Length-3,3)=="XML"))
					{
						fileOutType="NET";
						RB_Dekoder->Checked=true;
						RB_Koder->Checked=false;
					}
					TB_pathIn->Text=fullInPath;
					TB_pathOut->Text=fullInPath->Substring(0,fullInPath->Length-3)+fileOutType;
					myStream->Close();
					}
					}
					}
0

Mając nazwę pliku bezpiecznie możesz pobrać rozszerzenie (bez względu na jego długość i wielkość liter) w taki sposób:

String^ ext = System::IO::Path::GetExtension(this->openFileDialog1->FileName)->ToLower();

Uwaga - wynik zawiera kropkę ;)

0

ok to tez sie przyda :) ... bo wlasnie to mial byc nastepny krok :) dzieki

1 użytkowników online, w tym zalogowanych: 0, gości: 1