none
my program explodes with an invalid path error. RRS feed

  • Question

  • My program used to function perfectly minus i feature, it pulled a text file into a textbox window but I needed specific data and not the whole file.

    so, I added a vector (which had to be declared as a global).

    The act of displaying that vector is what is blowing up my program and line 409 of this code ->  http://pastie.org/4803115  (will post again at bottom)  "richTextBox1->LoadFile(newElement0, RichTextBoxStreamType::PlainText );" is where it blows up.

    line 130 begins the vector data retrieval http://pastie.org/4803225

    complete error ->  http://pastie.org/4800139

    ****************.cpp****************

    // entry point
    #include "stdafx.h"
    #include <windows.h>
    #include <iostream>
    #include <process.h>
    #include <string>
    #include <cstdlib>
    #include <commdlg.h>
    #include "Form1.h"
    #include <vector>
    #include <fstream>
    #include <sstream>
    #include <cstring>

    using namespace winForm1;
    using namespace std;
    using std::vector;
    using namespace System;
    #pragma comment(lib, "comdlg32.lib")

    //function prototypes
    void setTagName(string fileNameStr);
    void setffmpeg(string fileNameStr);
    void setmd5(string fileNameStr);
    std::string setValues_fromFfmpeg();

    // Open file dialog box
    string openfilename(char *filter = "All Files (*.*)\0*.*\0", HWND owner = NULL) {
    OPENFILENAME ofn;
    char fileName[MAX_PATH] = "";
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = owner;
    ofn.lpstrFilter  = filter;
    ofn.lpstrFile = fileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "";
    string fileNameStr;
    if ( GetOpenFileName(&ofn) )
    fileNameStr = fileName;
    return fileNameStr;
    }

    // Our 'MAIN' which initialize openfilename and setName
    [STAThreadAttribute]
    int main(array<System::String^> ^args)
    {
    setValues_fromFfmpeg();


    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 

    // Create the main window and run it
    Application::Run(gcnew Form1());
    //form1::button1_Click():
    return 0;
    }

    //function to dump media file idv3 tags using the DOS program tag
    void setTagName(string fileNameStr){
    {
    const int MAXITEMS = 7;
    string myList[MAXITEMS] = {"TITLE", "ARTIST", "ALBUM", "YEAR", "TRACK", "GENRE", "COMMENT"};
    //loop to inject myList array data one at a time because output in file delivers only first field
    for (int i = 0; i < MAXITEMS; i++)
    {
    //each time we have to cycle through for each tag
    string command = "tag --nocheck --tostdoutn \""+ myList[i]+"\" \"";
    command+= fileNameStr; command += "\" >> \"output.txt\"";
    system(command.c_str());
    //here we open file to add a new line
    ofstream myfile;
    myfile.open ("output.txt",ios_base::app);
    myfile << ":" + myList[i] + "\n";

    myfile.close();

    }
    }

    }
    //function to dump media file idv3 tags and file info using the DOS program ffmpeg
    void setffmpeg(string fileNameStr){
    string command = "ffmpeg -i ";
    command+= fileNameStr; command += "> ffmpeg.txt 2>>&1";
    system(command.c_str());
    }
    //function to dump md5 hash using md5deep
    void setmd5(string fileNameStr){
    string command = "md5deep ";
    command+= fileNameStr; command += "> md5.txt 2>>&1";
    system(command.c_str());
    };

    string setValues_fromFfmpeg(){
    //data collection process
    string fileNameStr;
    fileNameStr = openfilename();
    cout << fileNameStr.c_str();
    cin.ignore();
    setTagName(fileNameStr.c_str());
    setffmpeg(fileNameStr.c_str());
    setmd5(fileNameStr.c_str());
    //setValues_fromFfmpeg();

    //set array variable to be passed to display windows
    std::string filename("ffmpeg.txt");
    std::ifstream ifs(filename.c_str());
    const int MAXITEMS2 = 10;
    string myList2[10] = {"title", "comment", "rating", "artist", "album", "date", "track", "genre", "bitrate", "Duration"};
    std::stringstream oss;
    oss << ifs.rdbuf();
    if(!ifs && !ifs.eof())
    std::cerr << "Error reading file '" << filename << "'\n";
    std::string contents(oss.str());
    std::ofstream outFile;
    outFile.open("ffmpeg2.txt");
    //begin loop
    for (int i = 0; i < MAXITEMS2; i++)
    {
    size_t position = contents.find(myList2[i]);
    switch (i)
    {
    case 0:
    if(position != std::string::npos)
    {
    laVector.at(0)=contents.substr(position + 17, 31);
    }
    break;
    case 1:
    if(position != std::string::npos)
    {
    laVector.at(1)=contents.substr(position + 0, 26);
    //laVector.at(1)=myString1;
    //outFile << myString1 << endl;
    }
    break;
    case 2:
    if(position != std::string::npos)
    {
    laVector.at(2)=contents.substr(position + 0, 21);
    }
    break;
    case 3:
    if(position != std::string::npos)
    {
    laVector.at(3)=contents.substr(position + 0, 21);
    }
    break;
    case 4:
    if(position != std::string::npos)
    {
    laVector.at(4)=contents.substr(position + 0, 29);
    }
    break;
    case 5:
    if(position != std::string::npos)
    {
    laVector.at(5)=contents.substr(position + 0, 30);
    }
    break;
    case 6:
    if(position != std::string::npos)
    {
    laVector.at(6)=contents.substr(position + 0, 21);
    }
    break;
    case 7:
    if(position != std::string::npos)
    {
    laVector.at(7)=contents.substr(position + 0, 22);
    }
    break;
    case 8:
    if(position != std::string::npos)
    {
    laVector.at(8)=contents.substr(position + 0, 21);
    }
    break;
    case 9:
    if(position != std::string::npos)
    {
    laVector.at(9)=contents.substr(position + 0, 25);
    }
    break;
    default:
    if(position != std::string::npos)
    {
    }

    }
    }
    return "";
    }

    ***********************.h**********************

    #pragma once
    #include <string>
    #include <vector>

    using namespace std;
    using namespace System;
    using std::vector;

    std::vector<string> laVector(10);

    namespace winForm1{


    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    /// <summary>
    /// Summary for Form1
    /// </summary>

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1()
    {
    InitializeComponent();
    //constructor code
    }

    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::RichTextBox^  richTextBox1;
    protected: 
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::RichTextBox^  richTextBox2;
    private: System::Windows::Forms::RichTextBox^  richTextBox3;
    private: System::Windows::Forms::RichTextBox^  richTextBox4;
    private: System::Windows::Forms::RichTextBox^  richTextBox5;
    private: System::Windows::Forms::RichTextBox^  richTextBox6;
    private: System::Windows::Forms::RichTextBox^  richTextBox7;
    private: System::Windows::Forms::RichTextBox^  richTextBox8;
    private: System::Windows::Forms::RichTextBox^  richTextBox9;
    private: System::Windows::Forms::RichTextBox^  richTextBox10;
    private: System::Windows::Forms::RichTextBox^  richTextBox11;
    private: System::Windows::Forms::RichTextBox^  richTextBox12;
    private: System::Windows::Forms::Button^  button2;
    private: System::Windows::Forms::Button^  button3;
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::Label^  label4;
    private: System::Windows::Forms::Label^  label5;
    private: System::Windows::Forms::Label^  label6;
    private: System::Windows::Forms::Label^  label7;
    private: System::Windows::Forms::Label^  label8;
    private: System::Windows::Forms::Label^  label9;
    private: System::Windows::Forms::Label^  label10;
    private: System::Windows::Forms::Label^  label11;
    private: System::Windows::Forms::Label^  label12;

    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
    this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox4 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox5 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox6 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox7 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox8 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox9 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox10 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox11 = (gcnew System::Windows::Forms::RichTextBox());
    this->richTextBox12 = (gcnew System::Windows::Forms::RichTextBox());
    this->button2 = (gcnew System::Windows::Forms::Button());
    this->button3 = (gcnew System::Windows::Forms::Button());
    this->label1 = (gcnew System::Windows::Forms::Label());
    this->label2 = (gcnew System::Windows::Forms::Label());
    this->label3 = (gcnew System::Windows::Forms::Label());
    this->label4 = (gcnew System::Windows::Forms::Label());
    this->label5 = (gcnew System::Windows::Forms::Label());
    this->label6 = (gcnew System::Windows::Forms::Label());
    this->label7 = (gcnew System::Windows::Forms::Label());
    this->label8 = (gcnew System::Windows::Forms::Label());
    this->label9 = (gcnew System::Windows::Forms::Label());
    this->label10 = (gcnew System::Windows::Forms::Label());
    this->label11 = (gcnew System::Windows::Forms::Label());
    this->label12 = (gcnew System::Windows::Forms::Label());
    this->SuspendLayout();
    // 
    // richTextBox1
    // 
    this->richTextBox1->Location = System::Drawing::Point(40, 42);
    this->richTextBox1->Name = L"richTextBox1";
    this->richTextBox1->Size = System::Drawing::Size(100, 20);
    this->richTextBox1->TabIndex = 0;
    this->richTextBox1->Text = L"";
    this->richTextBox1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox1_TextChanged);
    // 
    // button1
    // 
    this->button1->Location = System::Drawing::Point(40, 320);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(75, 23);
    this->button1->TabIndex = 1;
    this->button1->Text = L"&FFmpeg";
    this->button1->UseVisualStyleBackColor = true;
    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    // 
    // richTextBox2
    // 
    this->richTextBox2->Location = System::Drawing::Point(146, 42);
    this->richTextBox2->Name = L"richTextBox2";
    this->richTextBox2->Size = System::Drawing::Size(100, 20);
    this->richTextBox2->TabIndex = 2;
    this->richTextBox2->Text = L"";
    this->richTextBox2->TextChanged += gcnew System::EventHandler(this, &Form1::richTextBox2_TextChanged);
    // 
    // richTextBox3
    // 
    this->richTextBox3->Location = System::Drawing::Point(252, 42);
    this->richTextBox3->Name = L"richTextBox3";
    this->richTextBox3->Size = System::Drawing::Size(100, 20);
    this->richTextBox3->TabIndex = 3;
    this->richTextBox3->Text = L"";
    // 
    // richTextBox4
    // 
    this->richTextBox4->Location = System::Drawing::Point(358, 42);
    this->richTextBox4->Name = L"richTextBox4";
    this->richTextBox4->Size = System::Drawing::Size(100, 20);
    this->richTextBox4->TabIndex = 4;
    this->richTextBox4->Text = L"";
    // 
    // richTextBox5
    // 
    this->richTextBox5->Location = System::Drawing::Point(40, 119);
    this->richTextBox5->Name = L"richTextBox5";
    this->richTextBox5->Size = System::Drawing::Size(100, 20);
    this->richTextBox5->TabIndex = 5;
    this->richTextBox5->Text = L"";
    // 
    // richTextBox6
    // 
    this->richTextBox6->Location = System::Drawing::Point(146, 119);
    this->richTextBox6->Name = L"richTextBox6";
    this->richTextBox6->Size = System::Drawing::Size(100, 20);
    this->richTextBox6->TabIndex = 6;
    this->richTextBox6->Text = L"";
    // 
    // richTextBox7
    // 
    this->richTextBox7->Location = System::Drawing::Point(252, 119);
    this->richTextBox7->Name = L"richTextBox7";
    this->richTextBox7->Size = System::Drawing::Size(100, 20);
    this->richTextBox7->TabIndex = 7;
    this->richTextBox7->Text = L"";
    // 
    // richTextBox8
    // 
    this->richTextBox8->Location = System::Drawing::Point(358, 119);
    this->richTextBox8->Name = L"richTextBox8";
    this->richTextBox8->Size = System::Drawing::Size(100, 20);
    this->richTextBox8->TabIndex = 8;
    this->richTextBox8->Text = L"";
    // 
    // richTextBox9
    // 
    this->richTextBox9->Location = System::Drawing::Point(40, 191);
    this->richTextBox9->Name = L"richTextBox9";
    this->richTextBox9->Size = System::Drawing::Size(100, 20);
    this->richTextBox9->TabIndex = 9;
    this->richTextBox9->Text = L"";
    // 
    // richTextBox10
    // 
    this->richTextBox10->Location = System::Drawing::Point(146, 191);
    this->richTextBox10->Name = L"richTextBox10";
    this->richTextBox10->Size = System::Drawing::Size(100, 20);
    this->richTextBox10->TabIndex = 10;
    this->richTextBox10->Text = L"";
    // 
    // richTextBox11
    // 
    this->richTextBox11->Location = System::Drawing::Point(252, 191);
    this->richTextBox11->Name = L"richTextBox11";
    this->richTextBox11->Size = System::Drawing::Size(100, 20);
    this->richTextBox11->TabIndex = 11;
    this->richTextBox11->Text = L"";
    // 
    // richTextBox12
    // 
    this->richTextBox12->Location = System::Drawing::Point(358, 191);
    this->richTextBox12->Name = L"richTextBox12";
    this->richTextBox12->Size = System::Drawing::Size(100, 20);
    this->richTextBox12->TabIndex = 12;
    this->richTextBox12->Text = L"";
    // 
    // button2
    // 
    this->button2->Location = System::Drawing::Point(146, 320);
    this->button2->Name = L"button2";
    this->button2->Size = System::Drawing::Size(75, 23);
    this->button2->TabIndex = 13;
    this->button2->Text = L"&IDv3";
    this->button2->UseVisualStyleBackColor = true;
    this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    // 
    // button3
    // 
    this->button3->Location = System::Drawing::Point(382, 320);
    this->button3->Name = L"button3";
    this->button3->Size = System::Drawing::Size(75, 23);
    this->button3->TabIndex = 14;
    this->button3->Text = L"&WriteXML";
    this->button3->UseVisualStyleBackColor = true;
    this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
    // 
    // label1
    // 
    this->label1->AutoSize = true;
    this->label1->Location = System::Drawing::Point(40, 26);
    this->label1->Name = L"label1";
    this->label1->Size = System::Drawing::Size(35, 13);
    this->label1->TabIndex = 15;
    this->label1->Text = L"Title";
    this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
    // 
    // label2
    // 
    this->label2->AutoSize = true;
    this->label2->Location = System::Drawing::Point(143, 26);
    this->label2->Name = L"label2";
    this->label2->Size = System::Drawing::Size(35, 13);
    this->label2->TabIndex = 16;
    this->label2->Text = L"Describtion";
    // 
    // label3
    // 
    this->label3->AutoSize = true;
    this->label3->Location = System::Drawing::Point(249, 26);
    this->label3->Name = L"label3";
    this->label3->Size = System::Drawing::Size(35, 13);
    this->label3->TabIndex = 17;
    this->label3->Text = L"Rating";
    // 
    // label4
    // 
    this->label4->AutoSize = true;
    this->label4->Location = System::Drawing::Point(355, 26);
    this->label4->Name = L"label4";
    this->label4->Size = System::Drawing::Size(35, 13);
    this->label4->TabIndex = 18;
    this->label4->Text = L"Artist";
    // 
    // label5
    // 
    this->label5->AutoSize = true;
    this->label5->Location = System::Drawing::Point(37, 103);
    this->label5->Name = L"label5";
    this->label5->Size = System::Drawing::Size(35, 13);
    this->label5->TabIndex = 19;
    this->label5->Text = L"Album";
    // 
    // label6
    // 
    this->label6->AutoSize = true;
    this->label6->Location = System::Drawing::Point(143, 103);
    this->label6->Name = L"label6";
    this->label6->Size = System::Drawing::Size(35, 13);
    this->label6->TabIndex = 20;
    this->label6->Text = L"Year";
    // 
    // label7
    // 
    this->label7->AutoSize = true;
    this->label7->Location = System::Drawing::Point(249, 103);
    this->label7->Name = L"label7";
    this->label7->Size = System::Drawing::Size(35, 13);
    this->label7->TabIndex = 21;
    this->label7->Text = L"Track";
    // 
    // label8
    // 
    this->label8->AutoSize = true;
    this->label8->Location = System::Drawing::Point(355, 103);
    this->label8->Name = L"label8";
    this->label8->Size = System::Drawing::Size(35, 13);
    this->label8->TabIndex = 22;
    this->label8->Text = L"Genre";
    // 
    // label9
    // 
    this->label9->AutoSize = true;
    this->label9->Location = System::Drawing::Point(40, 175);
    this->label9->Name = L"label9";
    this->label9->Size = System::Drawing::Size(35, 13);
    this->label9->TabIndex = 23;
    this->label9->Text = L"Comment";
    // 
    // label10
    // 
    this->label10->AutoSize = true;
    this->label10->Location = System::Drawing::Point(143, 175);
    this->label10->Name = L"label10";
    this->label10->Size = System::Drawing::Size(41, 13);
    this->label10->TabIndex = 24;
    this->label10->Text = L"Bitrate";
    // 
    // label11
    // 
    this->label11->AutoSize = true;
    this->label11->Location = System::Drawing::Point(249, 175);
    this->label11->Name = L"label11";
    this->label11->Size = System::Drawing::Size(41, 13);
    this->label11->TabIndex = 25;
    this->label11->Text = L"Duration";
    // 
    // label12
    // 
    this->label12->AutoSize = true;
    this->label12->Location = System::Drawing::Point(355, 175);
    this->label12->Name = L"label12";
    this->label12->Size = System::Drawing::Size(41, 13);
    this->label12->TabIndex = 26;
    this->label12->Text = L"Unused";
    // 
    // Form1
    // 
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(551, 368);
    this->Controls->Add(this->label12);
    this->Controls->Add(this->label11);
    this->Controls->Add(this->label10);
    this->Controls->Add(this->label9);
    this->Controls->Add(this->label8);
    this->Controls->Add(this->label7);
    this->Controls->Add(this->label6);
    this->Controls->Add(this->label5);
    this->Controls->Add(this->label4);
    this->Controls->Add(this->label3);
    this->Controls->Add(this->label2);
    this->Controls->Add(this->label1);
    this->Controls->Add(this->button3);
    this->Controls->Add(this->button2);
    this->Controls->Add(this->button1);
    this->Controls->Add(this->richTextBox12);
    this->Controls->Add(this->richTextBox11);
    this->Controls->Add(this->richTextBox10);
    this->Controls->Add(this->richTextBox9);
    this->Controls->Add(this->richTextBox8);
    this->Controls->Add(this->richTextBox7);
    this->Controls->Add(this->richTextBox6);
    this->Controls->Add(this->richTextBox5);
    this->Controls->Add(this->richTextBox4);
    this->Controls->Add(this->richTextBox3);
    this->Controls->Add(this->richTextBox2);
    this->Controls->Add(this->richTextBox1);
    this->Name = L"Form1";
    this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    this->ResumeLayout(false);
    this->PerformLayout();

    }
    #pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    LoadMyFile ();
    }
    private: System::Void richTextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {

    }
    private: System::Void richTextBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    }


    public: void LoadMyFile()
       {

             // Load the contents of the file into the RichTextBox.
    string element0;
    element0 = laVector.at(0);
    String^ newElement0 = gcnew String(element0.c_str());
    richTextBox1->LoadFile(newElement0, RichTextBoxStreamType::PlainText );


       }
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    }


    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
    }



    };
    }


    Wednesday, September 26, 2012 4:47 AM

Answers

All replies