I want to open a file dialog on windows to open a file with. This is my current code:
var openFileDialog : System.Windows.Forms.OpenFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = Application.dataPath; openFileDialog.Filter = "text files (*.txt)|*.txt"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = false; openFileDialog.ShowDialog();
It actually works fine after building my project and kinda okay, when executing it the first time from within Unity, but with the following message in the log:
IsD3D9DeviceLost() || g_D3DInsideScene System.Windows.Forms.XplatUIWin32:Win32GetMessage(MSG&, IntPtr, Int32, Int32) System.Windows.Forms.XplatUIWin32:Win32GetMessage(MSG&, IntPtr, Int32, Int32) System.Windows.Forms.XplatUIWin32:GetMessage(MSG&, IntPtr, Int32, Int32, Boolean) System.Windows.Forms.XplatUIWin32:GetMessage(Object, MSG&, IntPtr, Int32, Int32) System.Windows.Forms.XplatUI:GetMessage(Object, MSG&, IntPtr, Int32, Int32) System.Windows.Forms.Application:RunLoop(Boolean, ApplicationContext) System.Windows.Forms.Form:ShowDialog(IWin32Window) System.Windows.Forms.CommonDialog:ShowDialog(IWin32Window) System.Windows.Forms.CommonDialog:ShowDialog()
The dialog shows up, I can choose my file and open it. If I now leave Unity and am moving a bit through my folder structure using the explorer, I usually get the standart win 7 message that Unity doesnt react anymore. If I dont do this, but open another dialog, I get tons of error messages and in the end the same windows message. The error messages I get then look like this (as popup windows):
Oops: Could not register the window class, win32 error 0
Sometimes the form shows up a second time and everything works as the first time, but then after the third time opening the dialog Unity crashes.
It would be great if anyone could tell me what I am doing wrong and maybe how to solve it :) Thanks.