Firstly here is the code that im trying to get to work-
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ dlg = gcnew OpenFileDialog();
dlg->Filter = "Text Files|*.txt";
String^ stream;
if(dlg->ShowDialog()==Windows::Forms::DialogResult::OK)
{
txtOutput->Text = System::IO::File::ReadAllText(dlg->FileName);
char* num = (char*)(void*)Marshal::StringToHGlobalAnsi(stream); //Convert string to array of char
for (int i=0;i<stream->Length;++i) //ERRONEOUS LINE!!
{
num[i] = num[i] ^ key; //DECRYPT
}
String^ orig_stream = gcnew String(num);
txtOutput->Text = orig_stream;
}
}
Im trying to Open a File which is already encrypted. The program compiles w/o any errors, but during runtime it gives me the following error with the options to break, continue or abort:
An unhandled exception of type 'System.NullReferenceException' occurred in Project_Targaryen.exe
Additional information: Object reference not set to an instance of an object.
The error points to the for loop line.
Any help is appreciated!
streamis not associated with an object before it is used in the for loop.