Good day. I made a class for OpenFileDialog to work:
#include <Windows.h> enum DialogResult { OK, Cancel }; class IFileDialog { public: TCHAR FileName[MAX_PATH]; LPTSTR Title; virtual DialogResult Show() = 0; }; class COpenFileDialog : public IFileDialog { public: LPTSTR Filter; LPTSTR DefExt; COpenFileDialog(HWND hWnd); DialogResult Show(); private: OPENFILENAME m_ofn; }; COpenFileDialog::COpenFileDialog(HWND hWnd) { //FileName[0] = '\0'; ZeroMemory(&m_ofn, sizeof(m_ofn)); m_ofn.lStructSize = sizeof(m_ofn); m_ofn.hwndOwner = hWnd; m_ofn.lpstrFilter = Filter; m_ofn.nMaxFile = MAX_PATH; m_ofn.lpstrFile = FileName; m_ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; m_ofn.lpstrDefExt = DefExt; } DialogResult COpenFileDialog::Show() { return GetOpenFileName(&m_ofn) ? DialogResult::OK : DialogResult::Cancel; }
Then I try to call:
COpenFileDialog hDialog = COpenFileDialog(hMainWindow); hDialog.Filter = "M&B Scenes\0*.sco\0"; hDialog.DefExt = "sco"; hDialog.Title = ""; if(hDialog.Show() == DialogResult::OK) { //TODO }
But the program crashes on hDialog.Show()
, or rather when you call GetOpenFileName(&m_ofn)
:
Unhandled exception at 0x000007FDFC5D21A3 (SHCore.dll) in ScoEditor.exe: 0xC0000005: Access violation reading location 0x000000E600000000.
How can this be fixed?