-1

I tried to use OpenFileDialog in System.Windows.Forms, but when I switch the project build type from Mono to IL2CPP, it doesn't work anymore.
In IL2CPP mode i can still use the method by Win32 APIs, but I cannot find a valid solution of how to use IFileDialog COM Interface by P/Invoke.
This code doesn't working because the 'IFileDialog' is not defined:

[ComImport,Guid("d57c7288-d4ad-4768-be02-9d969532d960"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IFileOpenDialog : IFileDialog
    {
        // Defined on IModalWindow - repeated here due to requirements of COM interop layer
        // --------------------------------------------------------------------------------
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), PreserveSig]
        int Show([In] IntPtr parent);
// ......

Anyway, The API which came from Comdlg32.dll is still working, but it has many shortcomings(cannot remember the path of last selected file/folder and so on).
BTW, I want to not only create a File Selection/Save Dialog, but also create a Folder Selection Dialog.
Does IFileDialog have a switcher to allow me switch the dialog type? And, how to use IFileDialog COM Interface by P/Invoke in IL2CPP mode of Unity3D?
I will be appreciated if you could give me some valid solutions.

1 Answers1

0

May be off the point, but may solve your problem.

System.Windows.Forms in Unity IL2CPP does exactly works but need some changes.

I used the Unity Standalone File Browser before, that plugin has a dll file in .Net Framework 2.0. It works in Unity Mono Builds, but not in IL2CPP builds. In some attempts, I found that just change the System.Windows.Forms.dll into a .Net Framework 4.0 or newer one can solve the problem. After some works, System.Windows.Forms works fine in my project with Unity IL2CPP builds.

Hope I can help you.

yyyr
  • 16
  • 1
  • Just change the reference version of ```System.Windows.Forms.dll```? I will try it. – Misaka12456 May 29 '22 at 16:58
  • It cannot be compiled after I add a newer version reference of ```System.Windows.Forms```: ```ArgumentException: The Assembly Mono.WebBrowser is referenced by System.Windows.Forms ('Assets/System.Windows.Forms.dll'). But the dll is not allowed to be included or could not be found.``` – Misaka12456 May 29 '22 at 17:30
  • Also try to use newer version of `Mono.WebBrowser.dll`. – yyyr May 29 '22 at 17:34
  • Still not working... ```NotSupportedException: System.Drawing.Icon::.ctor``` – Misaka12456 May 29 '22 at 18:02
  • OK I know. Just change the version of ``System.Windows.Forms.dll`` to 4.0. – Misaka12456 Jun 06 '22 at 02:19