-
October 4th, 2021, 06:35 PM
#1
[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!
-
October 5th, 2021, 01:15 AM
#2
Re: openFileDialog - AccessViolationException was unhandled
What is openFileDialog1?
What is MyExcelFile?
Which line causes the exception?
Victor Nijegorodov
-
October 5th, 2021, 02:25 AM
#3
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
-
October 5th, 2021, 09:34 AM
#4
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
-
October 6th, 2021, 08:21 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|