Skip to content

Commit e593397

Browse files
virzakaugustoproiete
authored andcommitted
Use Microsoft.Windows.CsWin32 to generate P/Invoke methods
1 parent c29ffd7 commit e593397

23 files changed

+760
-1888
lines changed

src/Ookii.Dialogs.Wpf/AnimationResource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public static AnimationResource GetShellAnimation(ShellAnimation animation)
7474
return new AnimationResource("shell32.dll", (int)animation);
7575
}
7676

77-
internal SafeModuleHandle LoadLibrary()
77+
internal FreeLibrarySafeHandle LoadLibrary()
7878
{
79-
SafeModuleHandle handle = NativeMethods.LoadLibraryEx(ResourceFile, IntPtr.Zero, NativeMethods.LoadLibraryExFlags.LoadLibraryAsDatafile);
79+
var handle = NativeMethods.LoadLibraryEx(ResourceFile, default, Windows.Win32.System.LibraryLoader.LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_DATAFILE);
8080
if( handle.IsInvalid )
8181
{
8282
int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

src/Ookii.Dialogs.Wpf/ComCtlv6ActivationContext.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace Ookii.Dialogs.Wpf
2323
sealed class ComCtlv6ActivationContext : IDisposable
2424
{
2525
// Private data
26-
private IntPtr _cookie;
27-
private static NativeMethods.ACTCTX _enableThemingActivationContext;
28-
private static ActivationContextSafeHandle _activationContext;
26+
private nuint _cookie;
27+
private static ACTCTXW _enableThemingActivationContext;
28+
private static SafeFileHandle _activationContext;
2929
private static bool _contextCreationSucceeded;
3030
private static readonly object _contextCreationLock = new object();
3131

@@ -35,10 +35,10 @@ public ComCtlv6ActivationContext(bool enable)
3535
{
3636
if( EnsureActivateContextCreated() )
3737
{
38-
if( !NativeMethods.ActivateActCtx(_activationContext, out _cookie) )
38+
if( !NativeMethods.ActivateActCtx((HANDLE)_activationContext.DangerousGetHandle(), out _cookie) )
3939
{
4040
// Be sure cookie always zero if activation failed
41-
_cookie = IntPtr.Zero;
41+
_cookie = 0;
4242
}
4343
}
4444
}
@@ -57,12 +57,12 @@ public void Dispose()
5757

5858
private void Dispose(bool disposing)
5959
{
60-
if( _cookie != IntPtr.Zero )
60+
if( _cookie != 0 )
6161
{
6262
if( NativeMethods.DeactivateActCtx(0, _cookie) )
6363
{
6464
// deactivation succeeded...
65-
_cookie = IntPtr.Zero;
65+
_cookie = 0;
6666
}
6767
}
6868
}
@@ -95,15 +95,21 @@ private static bool EnsureActivateContextCreated()
9595
}
9696
}
9797

98-
_enableThemingActivationContext = new NativeMethods.ACTCTX
98+
unsafe
9999
{
100-
cbSize = Marshal.SizeOf(typeof(NativeMethods.ACTCTX)),
101-
lpSource = manifestTempFilePath,
102-
};
100+
fixed (char* szManifestTempFilePath = manifestTempFilePath)
101+
{
102+
_enableThemingActivationContext = new ACTCTXW
103+
{
104+
cbSize = (uint)Marshal.SizeOf(typeof(ACTCTXW)),
105+
lpSource = szManifestTempFilePath,
106+
};
107+
}
108+
}
103109

104110
// Note this will fail gracefully if file specified
105111
// by manifestFilePath doesn't exist.
106-
_activationContext = NativeMethods.CreateActCtx(ref _enableThemingActivationContext);
112+
_activationContext = NativeMethods.CreateActCtx(_enableThemingActivationContext);
107113
_contextCreationSucceeded = !_activationContext.IsInvalid;
108114

109115
try

src/Ookii.Dialogs.Wpf/CredentialDialog.cs

+189-143
Large diffs are not rendered by default.

src/Ookii.Dialogs.Wpf/Interop/COMGuids.cs

-23
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,13 @@
1414
//
1515
#endregion
1616

17-
using System;
18-
using System.Collections.Generic;
19-
using System.Linq;
20-
using System.Text;
21-
using System.Runtime.InteropServices;
22-
2317
namespace Ookii.Dialogs.Wpf.Interop
2418
{
2519
internal static class IIDGuid
2620
{
27-
internal const string IModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802";
28-
internal const string IFileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
2921
internal const string IFileOpenDialog = "d57c7288-d4ad-4768-be02-9d969532d960";
3022
internal const string IFileSaveDialog = "84bccd23-5fde-4cdb-aea4-af64b83d78ab";
31-
internal const string IFileDialogEvents = "973510DB-7D7F-452B-8975-74A85828D354";
32-
internal const string IFileDialogControlEvents = "36116642-D713-4b97-9B83-7484A9D00433";
33-
internal const string IFileDialogCustomize = "e6fdd21a-163f-4975-9c8c-a69f1ba37034";
34-
internal const string IShellItem = "43826D1E-E718-42EE-BC55-A1E261C37BFE";
35-
internal const string IShellItemArray = "B63EA76D-1F85-456F-A19C-48159EFA858B";
36-
internal const string IKnownFolder = "38521333-6A87-46A7-AE10-0F16706816C3";
3723
internal const string IKnownFolderManager = "44BEAAEC-24F4-4E90-B3F0-23D258FBB146";
38-
internal const string IPropertyStore = "886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99";
3924
internal const string IProgressDialog = "EBBC7C04-315E-11d2-B62F-006097DF5BD4";
4025
}
4126

@@ -46,12 +31,4 @@ internal static class CLSIDGuid
4631
internal const string KnownFolderManager = "4df0c730-df9d-4ae3-9153-aa6b82e9795a";
4732
internal const string ProgressDialog = "F8383852-FCD3-11d1-A6B9-006097DF5BD4";
4833
}
49-
50-
internal static class KFIDGuid
51-
{
52-
internal const string ComputerFolder = "0AC0837C-BBF8-452A-850D-79D08E667CA7";
53-
internal const string Favorites = "1777F761-68AD-4D8A-87BD-30B759FA33DD";
54-
internal const string Documents = "FDD39AD0-238F-46AF-ADB4-6C85480369C7";
55-
internal const string Profile = "5E6C858F-0E22-4760-9AFE-EA3317B67173";
56-
}
5734
}

src/Ookii.Dialogs.Wpf/Interop/ComDlgResources.cs

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
//
1515
#endregion
1616

17-
using System;
18-
using System.Collections.Generic;
19-
using System.Text;
20-
2117
namespace Ookii.Dialogs.Wpf.Interop
2218
{
2319
static class ComDlgResources

src/Ookii.Dialogs.Wpf/Interop/ErrorHelper.cs

-31
This file was deleted.

src/Ookii.Dialogs.Wpf/Interop/IProgressDialog.cs

-90
Original file line numberDiff line numberDiff line change
@@ -31,94 +31,4 @@ internal class ProgressDialogRCW
3131
internal interface ProgressDialog : IProgressDialog
3232
{
3333
}
34-
35-
[Flags]
36-
internal enum ProgressDialogFlags : uint
37-
{
38-
Normal = 0x00000000,
39-
Modal = 0x00000001,
40-
AutoTime = 0x00000002,
41-
NoTime = 0x00000004,
42-
NoMinimize = 0x00000008,
43-
NoProgressBar = 0x00000010,
44-
MarqueeProgress = 0x00000020,
45-
NoCancel = 0x00000040,
46-
}
47-
48-
[Flags]
49-
internal enum ProgressDialogTimerAction : uint
50-
{
51-
Reset = 0x00000001,
52-
Pause = 0x00000002,
53-
Resume = 0x00000003,
54-
}
55-
56-
[ComImport]
57-
[Guid(IIDGuid.IProgressDialog)]
58-
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
59-
internal interface IProgressDialog
60-
{
61-
62-
[PreserveSig]
63-
void StartProgressDialog(
64-
IntPtr hwndParent,
65-
[MarshalAs(UnmanagedType.IUnknown)]
66-
object punkEnableModless,
67-
ProgressDialogFlags dwFlags,
68-
IntPtr pvResevered
69-
);
70-
71-
[PreserveSig]
72-
void StopProgressDialog();
73-
74-
[PreserveSig]
75-
void SetTitle(
76-
[MarshalAs(UnmanagedType.LPWStr)]
77-
string pwzTitle
78-
);
79-
80-
[PreserveSig]
81-
void SetAnimation(
82-
SafeModuleHandle hInstAnimation,
83-
ushort idAnimation
84-
);
85-
86-
[PreserveSig]
87-
[return: MarshalAs(UnmanagedType.Bool)]
88-
bool HasUserCancelled();
89-
90-
[PreserveSig]
91-
void SetProgress(
92-
uint dwCompleted,
93-
uint dwTotal
94-
);
95-
[PreserveSig]
96-
void SetProgress64(
97-
ulong ullCompleted,
98-
ulong ullTotal
99-
);
100-
101-
[PreserveSig]
102-
void SetLine(
103-
uint dwLineNum,
104-
[MarshalAs(UnmanagedType.LPWStr)]
105-
string pwzString,
106-
[MarshalAs(UnmanagedType.VariantBool)]
107-
bool fCompactPath,
108-
IntPtr pvResevered
109-
);
110-
111-
[PreserveSig]
112-
void SetCancelMsg(
113-
[MarshalAs(UnmanagedType.LPWStr)]
114-
string pwzCancelMsg,
115-
object pvResevered
116-
);
117-
118-
[PreserveSig]
119-
void Timer(
120-
ProgressDialogTimerAction dwTimerAction,
121-
object pvReserved
122-
);
123-
}
12434
}

0 commit comments

Comments
 (0)