CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    70

    [RESOLVED] openFileDialog - AccessViolationException was unhandled

    Hi,
    Iam using Vs2015, While I try to Open a file using OpenFileDialog, Iam receiving the error

    "Unhandled exception of type" System.AccessViolationException" occoured in system.windows.forms.dll
    Additional information: Attempted to read or write protected memory.This is often an indication other memory is currupt.

    My Codes

    openFileDialog1->Title= "Select Your Excel File";
    openFileDialog1->InitialDirectory = "C:\";
    openFileDialog1->Filter = "Excel Files (.xls)|.xls|All files (.)|.";
    openFileDialog1->FilterIndex = 2;
    openFileDialog1->RestoreDirectory = true;
    if (openFileDialog1->ShowDialog() == System::Windows::Forms:ialogResult::OK) {
    MyExcelFile = openFileDialog1->FileName;
    }

    I cannot understand my mistake !
    Thanks For the helps!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,109

    Re: openFileDialog - AccessViolationException was unhandled

    What is openFileDialog1?
    What is MyExcelFile?
    Which line causes the exception?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2011
    Posts
    70

    Re: openFileDialog - AccessViolationException was unhandled

    Thank Victor. I always remember Eri523 & Victor. Because both are my Gurus. I learned many things from these gurus.
    First I wish to state my heartiest thanks to Eri523 & VioctorN.

    System::Windows::Forms::OpenFileDialog^ openFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog();
    String^ MyExcelFile = String::Empty;

    Exception raised in below codes...
    if (openFileDialog1->ShowDialog() == System::Windows::Forms:ialogResult::OK) {

    Kind Note : I tested in C# the same codes working fine, But in Visual C++ It's giving problem...

    Thank Again

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,109

    Re: openFileDialog - AccessViolationException was unhandled

    This code:
    Code:
    using namespace System;
    using namespace System::Windows;
    using namespace Forms;
    
    [STAThread]
    int main(array<System::String ^> ^args)
    {
       String^ MyExcelFile = String::Empty;
    
       System::Windows::Forms::OpenFileDialog^ openFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog(); 
       openFileDialog1->Title = "Select Your Excel File";
       openFileDialog1->InitialDirectory = "C:\";
       openFileDialog1->Filter = "Excel Files (.xls)|.xls|All files (.)|.";
       openFileDialog1->FilterIndex = 2;
       openFileDialog1->RestoreDirectory = true;
       if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
       {
          MyExcelFile = openFileDialog1->FileName;
       }
       return 0;
    }
    works without exceptions. Note the [STAThread] before the main function.
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2011
    Posts
    70

    Re: [RESOLVED] openFileDialog - AccessViolationException was unhandled

    Always Thanks To Those Kind Hearts Victor !

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured