I am writing a simple application (CodeBlocks, minGW, wxWidgets 3.1.2), which has 2 buttons. First one loads binary file, second one saves data from binary file in human readable format. I'm using FileDialog for choosing binary and text file.
Button1 function for browsing is this:
Code: Select all
void Binary_ReaderFrame::OnButton1Click(wxCommandEvent& event)
{
string f;
if (FileDialog1->ShowModal() == wxID_OK)
{
f = string((FileDialog1->GetPath()).mb_str());
auto found = f.find_last_of(".");
if (found != string::npos && f.substr(found).compare(".bin"))
{
wxMessageBox(_("Wrong file chosen.\n"));
return;
}
}
else
{
wxMessageBox(_("Error loading file.\n"));
return;
}
StatusBar1->SetStatusText("BIN file: " + FileDialog1->GetPath());
}
Code: Select all
void Binary_ReaderFrame::OnButton2Click(wxCommandEvent& event)
{
string f = string((FileDialog1->GetPath()).mb_str());
string f2 = "";
if (f.empty())
{
wxMessageBox(_("Please first choose binary file."));
return;
}
if (FileDialog2->ShowModal() == wxID_OK)
{
f2 = string((FileDialog2->GetPath()).mb_str());
auto found = f2.find_last_of(".");
if (found != string::npos && f2.substr(found).compare(".txt"))
{
wxMessageBox(_("Wrong file chosen.\n"));
return;
}
}
else
{
StatusBar1->SetStatusText("Error loading file.");
return;
}
wxMessageBox("1");
ifstream in(f, ios::binary | ios::in);
wxMessageBox("1.5");
ofstream out(f2);
while(in)
{
int8_t x;
in.read((char*)&x, 1);
x -= 99;
out << x;
}
in.close();
out.close();
wxMessageBox(_("Finished.\n"));
}
Now to the problem. The application runs and works fine when runninng through IDE (CodeBlocks), but when I run it as standalone application (\bin\Release\[name].exe), the application crashes at:
Code: Select all
ifstream in(f, ios::binary | ios::in);
If it helps, I built wxWidgets as:
Code: Select all
C:\MinGW\bin\mingw32-make -f makefile.gcc -j4 BUILD=debug MONOLITHIC=0 RUNTIME_LIBS=static SHARED=0