Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CsWin32 version (#137) #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ The `Ookii.Dialogs.Wpf.VistaOpenFileDialog`, `Ookii.Dialogs.Wpf.VistaSaveFileDia

The classes have been designed to resemble the original WPF classes to make it easy to switch. When the classes are used on Windows XP, they will automatically fall back to the old style dialog; this is also true for the `VistaFolderBrowserDialog`; that class provides a complete implementation of a folder browser dialog for WPF, old as well as new style.

## .NET Core 3.1 & .NET 5 pre-requisites **before** Ookii.Dialogs.Wpf v3.1.0
## .NET 5 pre-requisites **before** Ookii.Dialogs.Wpf v3.1.0

> **NOTE: Starting with Ookii.Dialogs.Wpf v3.1.0 an app.manifest is no longer required when using in .NET 5 or .NET Core 3.1 apps**
> **NOTE: Starting with Ookii.Dialogs.Wpf v3.1.0 an app.manifest is no longer required when using in .NET 5 apps**

Ookii Dialogs leverages the components and visual styles of the Windows Common Controls library (`comctl32.dll`), and WPF applications targeting .NET Core 3.1 and/or .NET 5 must add an [application manifest](https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests) (`app.manifest`) to their projects with a reference to `Microsoft.Windows.Common-Controls`.
Ookii Dialogs leverages the components and visual styles of the Windows Common Controls library (`comctl32.dll`), and WPF applications targeting .NET 5 must add an [application manifest](https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests) (`app.manifest`) to their projects with a reference to `Microsoft.Windows.Common-Controls`.

Without the application manifest, you'll get an error with a message similar to the below:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>net6.0-windows;net5.0-windows;netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0-windows;net5.0-windows;net462</TargetFrameworks>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
Expand Down
2 changes: 1 addition & 1 deletion src/Ookii.Dialogs.Wpf/AnimationResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static AnimationResource GetShellAnimation(ShellAnimation animation)

internal FreeLibrarySafeHandle LoadLibrary()
{
var handle = NativeMethods.LoadLibraryEx(ResourceFile, default, Windows.Win32.System.LibraryLoader.LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_DATAFILE);
var handle = NativeMethods.LoadLibraryEx(ResourceFile, Windows.Win32.System.LibraryLoader.LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_DATAFILE);
if( handle.IsInvalid )
{
int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
Expand Down
2 changes: 1 addition & 1 deletion src/Ookii.Dialogs.Wpf/ComCtlv6ActivationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sealed class ComCtlv6ActivationContext : IDisposable
// Private data
private nuint _cookie;
private static ACTCTXW _enableThemingActivationContext;
private static SafeFileHandle _activationContext;
private static ReleaseActCtxSafeHandle _activationContext;
private static bool _contextCreationSucceeded;
private static readonly object _contextCreationLock = new object();

Expand Down
6 changes: 3 additions & 3 deletions src/Ookii.Dialogs.Wpf/CredentialDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public unsafe static NetworkCredential RetrieveCredential(string target, byte[]
if (cred != null)
return cred;

var result = NativeMethods.CredRead(target, (uint)CRED_TYPE.CRED_TYPE_GENERIC, 0, out var credential);
var result = NativeMethods.CredRead(target, (uint)CRED_TYPE.CRED_TYPE_GENERIC, out var credential);
int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
if (result)
{
Expand Down Expand Up @@ -759,7 +759,7 @@ public static bool DeleteCredential(string target)
found = _applicationInstanceCredentialCache.Remove(target);
}

if (NativeMethods.CredDelete(target, (uint)CRED_TYPE.CRED_TYPE_GENERIC, 0))
if (NativeMethods.CredDelete(target, (uint)CRED_TYPE.CRED_TYPE_GENERIC))
{
found = true;
}
Expand Down Expand Up @@ -805,7 +805,7 @@ private unsafe bool PromptForCredentialsCredUI(HWND owner, bool storedCredential
Password.AsSpan().CopyTo(pwSpan);
WIN32_ERROR result;
fixed (BOOL* b = &_isSaveChecked)
result = (WIN32_ERROR)NativeMethods.CredUIPromptForCredentials(info, Target, ref Unsafe.AsRef<SecHandle>((void*)0), 0, ref userSpan, NativeMethods.CREDUI_MAX_USERNAME_LENGTH, ref pwSpan, NativeMethods.CREDUI_MAX_PASSWORD_LENGTH, b, flags);
result = (WIN32_ERROR)NativeMethods.CredUIPromptForCredentials(info, Target, 0, ref userSpan, NativeMethods.CREDUI_MAX_USERNAME_LENGTH, ref pwSpan, NativeMethods.CREDUI_MAX_PASSWORD_LENGTH, b, flags);

switch (result)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ookii.Dialogs.Wpf/Interop/Win32Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Win32Resources : IDisposable

public Win32Resources(string module)
{
_moduleHandle = NativeMethods.LoadLibraryEx(module, default, LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_DATAFILE);
_moduleHandle = NativeMethods.LoadLibraryEx(module, LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_DATAFILE);
if (_moduleHandle.IsInvalid)
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
}
Expand Down
8 changes: 2 additions & 6 deletions src/Ookii.Dialogs.Wpf/Ookii.Dialogs.Wpf.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>net6.0-windows;net5.0-windows;netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0-windows;net5.0-windows;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>Ookii.Dialogs.Wpf</RootNamespace>
Expand Down Expand Up @@ -54,10 +54,6 @@
<DefineConstants>$(DefineConstants);NETFX</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);NETCORE31</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0-windows' ">
<DefineConstants>$(DefineConstants);NET5</DefineConstants>
</PropertyGroup>
Expand All @@ -68,7 +64,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.252-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)'=='net462'" />
</ItemGroup>

Expand Down
14 changes: 7 additions & 7 deletions src/Ookii.Dialogs.Wpf/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public string Text
unsafe
{
if (_dialog != null)
_dialog.SetLine(1, Text, UseCompactPathsForText, default);
_dialog.SetLine(1, Text, UseCompactPathsForText);
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public bool UseCompactPathsForText
unsafe
{
if ( _dialog != null )
_dialog.SetLine(1, Text, UseCompactPathsForText, default);
_dialog.SetLine(1, Text, UseCompactPathsForText);
}
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public string Description
unsafe
{
if (_dialog != null)
_dialog.SetLine(2, Description, UseCompactPathsForDescription, default);
_dialog.SetLine(2, Description, UseCompactPathsForDescription);
}
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public bool UseCompactPathsForDescription
unsafe
{
if (_dialog != null)
_dialog.SetLine(2, Description, UseCompactPathsForDescription, default);
_dialog.SetLine(2, Description, UseCompactPathsForDescription);
}
}
}
Expand Down Expand Up @@ -772,9 +772,9 @@ private unsafe void RunProgressDialog(IntPtr owner, object argument, Cancellatio
_dialog.SetAnimation(_currentAnimationModuleHandle, (ushort)Animation.ResourceId);

if( CancellationText.Length > 0 )
_dialog.SetCancelMsg(CancellationText, null);
_dialog.SetLine(1, Text, UseCompactPathsForText, default);
_dialog.SetLine(2, Description, UseCompactPathsForDescription, default);
_dialog.SetCancelMsg(CancellationText);
_dialog.SetLine(1, Text, UseCompactPathsForText);
_dialog.SetLine(2, Description, UseCompactPathsForDescription);

uint flags = NativeMethods.PROGDLG_NORMAL;
if( owner != IntPtr.Zero )
Expand Down
5 changes: 3 additions & 2 deletions src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ private bool RunDialog(HWND owner)
private unsafe bool RunDialogDownlevel(HWND owner)
{
IntPtr resultItemIdList = IntPtr.Zero;
if (NativeMethods.SHGetSpecialFolderLocation(owner, (int)RootFolder, out ITEMIDLIST* rootItemIdList) != HRESULT.S_OK)
ITEMIDLIST* rootItemIdList;
if (NativeMethods.SHGetSpecialFolderLocation(owner, (int)RootFolder, &rootItemIdList) != HRESULT.S_OK)
{
if (NativeMethods.SHGetSpecialFolderLocation(owner, 0, out rootItemIdList) != 0)
if (NativeMethods.SHGetSpecialFolderLocation(owner, 0, &rootItemIdList) != 0)
{
throw new InvalidOperationException(Properties.Resources.FolderBrowserDialogNoRootFolder);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Ookii.Dialogs.Wpf/VistaOpenFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ internal unsafe override void GetResult(IFileDialog dialog)
if( ShowReadOnly )
{
IFileDialogCustomize customize = (IFileDialogCustomize)dialog;
uint selected;
customize.GetSelectedControlItem(_openDropDownId, &selected);
customize.GetSelectedControlItem(_openDropDownId, out var selected);
_readOnlyChecked = (selected == _readOnlyItemId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ookii.Dialogs/Ookii.Dialogs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>net6.0-windows;net5.0-windows;netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net6.0-windows;net5.0-windows;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>

Expand Down