diff --git a/NativeFileDialogSharp.sln b/NativeFileDialogSharp.sln index c95c259..db33b15 100644 --- a/NativeFileDialogSharp.sln +++ b/NativeFileDialogSharp.sln @@ -13,34 +13,48 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|Any CPU.Build.0 = Debug|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|x64.ActiveCfg = Debug|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|x64.Build.0 = Debug|Any CPU + {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|x86.ActiveCfg = Debug|Any CPU + {4127F279-9FD5-4C37-B904-242C124C1A07}.Debug|x86.Build.0 = Debug|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|Any CPU.ActiveCfg = Release|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|Any CPU.Build.0 = Release|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|x64.ActiveCfg = Release|Any CPU {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|x64.Build.0 = Release|Any CPU + {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|x86.ActiveCfg = Release|Any CPU + {4127F279-9FD5-4C37-B904-242C124C1A07}.Release|x86.Build.0 = Release|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|Any CPU.Build.0 = Debug|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|x64.ActiveCfg = Debug|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|x64.Build.0 = Debug|Any CPU + {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|x86.ActiveCfg = Debug|Any CPU + {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Debug|x86.Build.0 = Debug|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|Any CPU.ActiveCfg = Release|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|Any CPU.Build.0 = Release|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|x64.ActiveCfg = Release|Any CPU {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|x64.Build.0 = Release|Any CPU + {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|x86.ActiveCfg = Release|Any CPU + {427E5F76-8418-4EA3-9AA3-C1DBFDE0478F}.Release|x86.Build.0 = Release|Any CPU {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|x64.ActiveCfg = Debug|x64 {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|x64.Build.0 = Debug|x64 + {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|x86.ActiveCfg = Debug|x86 + {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Debug|x86.Build.0 = Debug|x86 {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|Any CPU.ActiveCfg = Release|Any CPU {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|Any CPU.Build.0 = Release|Any CPU {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|x64.ActiveCfg = Release|x64 {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|x64.Build.0 = Release|x64 + {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|x86.ActiveCfg = Release|x86 + {0FD91168-D8F5-4776-8D91-CB9B9C55AA1B}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NativeFileDialogSharp/NativeFileDialogSharp.csproj b/NativeFileDialogSharp/NativeFileDialogSharp.csproj index 87a0602..bbfcf40 100644 --- a/NativeFileDialogSharp/NativeFileDialogSharp.csproj +++ b/NativeFileDialogSharp/NativeFileDialogSharp.csproj @@ -15,6 +15,12 @@ + + PreserveNewest + + + PreserveNewest + diff --git a/NativeFileDialogSharp/NativeWrappers.cs b/NativeFileDialogSharp/NativeWrappers.cs index 42e02f0..54f41d4 100644 --- a/NativeFileDialogSharp/NativeWrappers.cs +++ b/NativeFileDialogSharp/NativeWrappers.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; using NativeFileDialogSharp.Native; @@ -10,6 +11,32 @@ namespace NativeFileDialogSharp { private static readonly Encoder utf8encoder = Encoding.UTF8.GetEncoder(); + private static readonly bool need32bit = Is32BitWindowsOnNetFramework(); + + private static bool Is32BitWindowsOnNetFramework() + { + try + { + // we call a function that does nothing just to test if we can load it properly + NativeFileDialogSharp.Native.NativeFunctions.NFD_Dummy(); + return false; + } + catch + { + // a call to a default library failed, let's attempt the other one + try + { + NativeFileDialogSharp.Native.NativeFunctions32.NFD_Dummy(); + return true; + } + catch + { + // both of them failed so we may as well default to the default one for predictability + return false; + } + } + } + private static unsafe byte[] ToUtf8(string s) { var byteCount = Encoding.UTF8.GetByteCount(s); @@ -50,7 +77,10 @@ namespace NativeFileDialogSharp { string path = null; string errorMessage = null; - var result = NativeFunctions.NFD_OpenDialog(filterListNts, defaultPathNts, out IntPtr outPathIntPtr); + IntPtr outPathIntPtr; + var result = need32bit + ? NativeFunctions32.NFD_OpenDialog(filterListNts, defaultPathNts, out outPathIntPtr) + : NativeFunctions.NFD_OpenDialog(filterListNts, defaultPathNts, out outPathIntPtr); if (result == nfdresult_t.NFD_ERROR) { errorMessage = FromUtf8(NativeFunctions.NFD_GetError()); @@ -73,7 +103,10 @@ namespace NativeFileDialogSharp { string path = null; string errorMessage = null; - var result = NativeFunctions.NFD_SaveDialog(filterListNts, defaultPathNts, out IntPtr outPathIntPtr); + IntPtr outPathIntPtr; + var result = need32bit + ? NativeFunctions32.NFD_SaveDialog(filterListNts, defaultPathNts, out outPathIntPtr) + : NativeFunctions.NFD_SaveDialog(filterListNts, defaultPathNts, out outPathIntPtr); if (result == nfdresult_t.NFD_ERROR) { errorMessage = FromUtf8(NativeFunctions.NFD_GetError()); @@ -95,7 +128,10 @@ namespace NativeFileDialogSharp { string path = null; string errorMessage = null; - var result = NativeFunctions.NFD_PickFolder(defaultPathNts, out IntPtr outPathIntPtr); + IntPtr outPathIntPtr; + var result = need32bit + ? NativeFunctions32.NFD_PickFolder(defaultPathNts, out outPathIntPtr) + : NativeFunctions.NFD_PickFolder(defaultPathNts, out outPathIntPtr); if (result == nfdresult_t.NFD_ERROR) { errorMessage = FromUtf8(NativeFunctions.NFD_GetError()); @@ -119,7 +155,9 @@ namespace NativeFileDialogSharp List paths = null; string errorMessage = null; nfdpathset_t pathSet; - var result = NativeFunctions.NFD_OpenDialogMultiple(filterListNts, defaultPathNts, &pathSet); + var result = need32bit + ? NativeFunctions32.NFD_OpenDialogMultiple(filterListNts, defaultPathNts, &pathSet) + : NativeFunctions.NFD_OpenDialogMultiple(filterListNts, defaultPathNts, &pathSet); if (result == nfdresult_t.NFD_ERROR) { errorMessage = FromUtf8(NativeFunctions.NFD_GetError()); diff --git a/NativeFileDialogSharp/nfd.dll b/NativeFileDialogSharp/nfd.dll new file mode 100644 index 0000000..76865ae Binary files /dev/null and b/NativeFileDialogSharp/nfd.dll differ diff --git a/NativeFileDialogSharp/nfd_x86.dll b/NativeFileDialogSharp/nfd_x86.dll new file mode 100644 index 0000000..4aa6782 Binary files /dev/null and b/NativeFileDialogSharp/nfd_x86.dll differ diff --git a/NativeFileDialogSharpSandboxNetFramework/NativeFileDialogSharpSandboxNetFramework.csproj b/NativeFileDialogSharpSandboxNetFramework/NativeFileDialogSharpSandboxNetFramework.csproj index 9629bee..b460e14 100644 --- a/NativeFileDialogSharpSandboxNetFramework/NativeFileDialogSharpSandboxNetFramework.csproj +++ b/NativeFileDialogSharpSandboxNetFramework/NativeFileDialogSharpSandboxNetFramework.csproj @@ -53,9 +53,29 @@ prompt true + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + true + - ..\packages\NativeFileDialogSharp.0.4.4\lib\net461\NativeFileDialogSharp.dll + ..\packages\NativeFileDialogSharp.0.5.0\lib\netstandard2.0\NativeFileDialogSharp.dll @@ -74,5 +94,9 @@ + + + + \ No newline at end of file diff --git a/NativeFileDialogSharpSandboxNetFramework/nfd.dll b/NativeFileDialogSharpSandboxNetFramework/nfd.dll new file mode 100644 index 0000000..76865ae Binary files /dev/null and b/NativeFileDialogSharpSandboxNetFramework/nfd.dll differ diff --git a/NativeFileDialogSharpSandboxNetFramework/nfd_x86.dll b/NativeFileDialogSharpSandboxNetFramework/nfd_x86.dll new file mode 100644 index 0000000..4aa6782 Binary files /dev/null and b/NativeFileDialogSharpSandboxNetFramework/nfd_x86.dll differ diff --git a/NativeFileDialogSharpSandboxNetFramework/packages.config b/NativeFileDialogSharpSandboxNetFramework/packages.config index 7826378..8336421 100644 --- a/NativeFileDialogSharpSandboxNetFramework/packages.config +++ b/NativeFileDialogSharpSandboxNetFramework/packages.config @@ -1,5 +1,4 @@  - - + \ No newline at end of file