简体   繁体   中英

How to use IFileDialog COM Interface by P/Invoke in IL2CPP mode of Unity3D?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM