Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

internal static partial class Interop
Expand All @@ -27,10 +28,11 @@ public struct ToolInfoWrapper<T>
where T : IHandle
{
public TTOOLINFOW Info;
public string Text { get; set; }
public string? Text { get; set; }
[MaybeNull]
private readonly T _handle;

public unsafe ToolInfoWrapper(T handle, TTF flags = default, string text = null)
public unsafe ToolInfoWrapper(T handle, TTF flags = default, string? text = null)
{
Info = new TTOOLINFOW
{
Expand All @@ -42,7 +44,7 @@ public unsafe ToolInfoWrapper(T handle, TTF flags = default, string text = null)
_handle = handle;
}

public unsafe ToolInfoWrapper(T handle, IntPtr id, TTF flags = default, string text = null, RECT rect = default)
public unsafe ToolInfoWrapper(T handle, IntPtr id, TTF flags = default, string? text = null, RECT rect = default)
{
Info = new TTOOLINFOW
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct BITMAPINFO
public BITMAPINFOHEADER bmiHeader;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxColorSize * 4)]
public byte[] bmiColors; // RGBQUAD structs: repeating Blue-Green-Red-Reserved
public byte[]? bmiColors; // RGBQUAD structs: repeating Blue-Green-Red-Reserved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class OLEVERB
{
public OLEIVERB lVerb;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszVerbName;
public string? lpszVerbName;
public User32.MF fuFlags;
public OLEVERBATTRIB grfAttribs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ internal static partial class Ole32
public sealed class QACONTAINER
{
public uint cbSize;
public IOleClientSite pClientSite;
public IAdviseSink pAdviseSink;
public IPropertyNotifySink pPropertyNotifySink;
public IOleClientSite? pClientSite;
public IAdviseSink? pAdviseSink;
public IPropertyNotifySink? pPropertyNotifySink;
[MarshalAs(UnmanagedType.Interface)]
public object pUnkEventSink;
public object? pUnkEventSink;
public QACONTAINERFLAGS dwAmbientFlags;
public uint colorFore;
public uint colorBack;
public IFont pFont;
public IFont? pFont;
public IntPtr pUndoMgr;
public uint dwAppearance;
public int lcid;
public IntPtr hpal;
public IServiceProvider pBindHost;
public IServiceProvider? pBindHost;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct STATSTG
public uint grfStateBits;
public uint reserved;

public string GetName() => Marshal.PtrToStringUni(pwcsName);
public string? GetName() => Marshal.PtrToStringUni(pwcsName);

/// <summary>
/// Caller is responsible for freeing the name memory.
Expand All @@ -76,7 +76,7 @@ public void FreeName()
/// <summary>
/// Callee is repsonsible for allocating the name memory.
/// </summary>
public void AllocName(string name)
public void AllocName(string? name)
{
pwcsName = Marshal.StringToCoTaskMemUni(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Clear()

~VARIANT() => Clear();

public object ToObject()
public object? ToObject()
{
IntPtr val = data1;
long longVal;
Expand Down Expand Up @@ -165,8 +165,8 @@ public object ToObject()
return (val != IntPtr.Zero);

case VARENUM.VARIANT:
VARIANT varStruct = Marshal.PtrToStructure<VARIANT>(val);
return varStruct.ToObject();
VARIANT? varStruct = Marshal.PtrToStructure<VARIANT>(val);
return varStruct?.ToObject();

case VARENUM.CLSID:
Guid guid = Marshal.PtrToStructure<Guid>(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static partial class Oleaut32
public struct FONTDESC
{
public uint cbSizeOfStruct;
public string lpstrName;
public string? lpstrName;
public long cySize;
public short sWeight;
public short sCharset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static partial class Interop
internal static partial class Shell32
{
[DllImport(Libraries.Shell32, ExactSpelling = true, EntryPoint = "DragQueryFileW", CharSet = CharSet.Unicode)]
private static extern uint DragQueryFileWInternal(IntPtr hDrop, uint iFile, StringBuilder lpszFile, uint cch);
private static extern uint DragQueryFileWInternal(IntPtr hDrop, uint iFile, StringBuilder? lpszFile, uint cch);

public static uint DragQueryFileW(IntPtr hDrop, uint iFile, StringBuilder lpszFile)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public unsafe struct BROWSEINFO
{
public IntPtr hwndOwner;

public CoTaskMemSafeHandle pidlRoot;
public CoTaskMemSafeHandle? pidlRoot;

public char* pszDisplayName;

public string lpszTitle;
public string? lpszTitle;

public uint ulFlags;

public BrowseCallbackProc lpfn;
public BrowseCallbackProc? lpfn;

public IntPtr lParam;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static partial class Shell32
[DllImport(Libraries.Shell32, ExactSpelling = true)]
private static extern BOOL SHGetPathFromIDListEx(IntPtr pidl, IntPtr pszPath, int cchPath, int flags);

public static bool SHGetPathFromIDListLongPath(IntPtr pidl, out string path)
public static bool SHGetPathFromIDListLongPath(IntPtr pidl, out string? path)
{
IntPtr pszPath = Marshal.AllocHGlobal((Kernel32.MAX_PATH + 1) * sizeof(char));
int length = Kernel32.MAX_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct DEVMODEW
private const int CCHFORMNAME = 32;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
public string dmDeviceName;
public string? dmDeviceName;
public ushort dmSpecVersion;
public ushort dmDriverVersion;
public ushort dmSize;
Expand All @@ -33,7 +33,7 @@ public struct DEVMODEW
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
public string dmFormName;
public string? dmFormName;
public ushort dmLogPixels;
public uint dmBitsPerPel;
public uint dmPelsWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static BOOL EnumChildWindows(HandleRef hwndParent, EnumChildWindowsCallba

private static BOOL HandleEnumChildWindowsNativeCallback(IntPtr hWnd, IntPtr lParam)
{
return ((EnumChildWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd);
return ((EnumChildWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static BOOL EnumThreadWindows(uint dwThreadId, EnumThreadWindowsCallback

private static BOOL HandleEnumThreadWindowsNativeCallback(IntPtr hWnd, IntPtr lParam)
{
return ((EnumThreadWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd);
return ((EnumThreadWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static BOOL EnumWindows(EnumWindowsCallback lpEnumFunc)

private static BOOL HandleEnumWindowsNativeCallback(IntPtr hWnd, IntPtr lParam)
{
return ((EnumWindowsCallback)GCHandle.FromIntPtr(lParam).Target)(hWnd);
return ((EnumWindowsCallback)GCHandle.FromIntPtr(lParam).Target!)(hWnd);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static partial class User32
[DllImport(Libraries.User32, ExactSpelling = true)]
private static unsafe extern int GetClipboardFormatNameW(uint format, char* lpszFormatName, int cchMaxCount);

public static unsafe string GetClipboardFormatNameW(uint format)
public static unsafe string? GetClipboardFormatNameW(uint format)
{
// The max length of the name of clipboard formats is equal to the max length
// of a Win32 Atom of 255 chars. An additional null terminator character is added,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<AssemblyName>System.Windows.Forms.Primitives</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>true</CLSCompliant>
<Nullable>enable</Nullable>
<!--the obsolete usage in public surface can't be removed-->
<NoWarn>$(NoWarn);618</NoWarn>
<Deterministic>true</Deterministic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ namespace System.ComponentModel
{
internal static class CompModSwitches
{
private static TraceSwitch activeX;
private static TraceSwitch flowLayout;
private static TraceSwitch dataCursor;
private static TraceSwitch dataGridCursor;
private static TraceSwitch dataGridEditing;
private static TraceSwitch dataGridKeys;
private static TraceSwitch dataGridLayout;
private static TraceSwitch dataGridPainting;
private static TraceSwitch dataGridParents;
private static TraceSwitch dataGridScrolling;
private static TraceSwitch dataGridSelection;
private static TraceSwitch dataObject;
private static TraceSwitch dataView;
private static TraceSwitch debugGridView;
private static TraceSwitch dgCaptionPaint;
private static TraceSwitch dgEditColumnEditing;
private static TraceSwitch dgRelationShpRowLayout;
private static TraceSwitch dgRelationShpRowPaint;
private static TraceSwitch dgRowPaint;
private static TraceSwitch dragDrop;
private static TraceSwitch imeMode;
private static TraceSwitch msaa;
private static TraceSwitch msoComponentManager;
private static TraceSwitch layoutPerformance;
private static TraceSwitch layoutSuspendResume;
private static TraceSwitch richLayout;
private static TraceSwitch setBounds;

private static BooleanSwitch lifetimeTracing;

private static TraceSwitch s_handleLeak;
private static BooleanSwitch s_traceCollect;
private static BooleanSwitch s_commonDesignerServices;
private static TraceSwitch? activeX;
private static TraceSwitch? flowLayout;
private static TraceSwitch? dataCursor;
private static TraceSwitch? dataGridCursor;
private static TraceSwitch? dataGridEditing;
private static TraceSwitch? dataGridKeys;
private static TraceSwitch? dataGridLayout;
private static TraceSwitch? dataGridPainting;
private static TraceSwitch? dataGridParents;
private static TraceSwitch? dataGridScrolling;
private static TraceSwitch? dataGridSelection;
private static TraceSwitch? dataObject;
private static TraceSwitch? dataView;
private static TraceSwitch? debugGridView;
private static TraceSwitch? dgCaptionPaint;
private static TraceSwitch? dgEditColumnEditing;
private static TraceSwitch? dgRelationShpRowLayout;
private static TraceSwitch? dgRelationShpRowPaint;
private static TraceSwitch? dgRowPaint;
private static TraceSwitch? dragDrop;
private static TraceSwitch? imeMode;
private static TraceSwitch? msaa;
private static TraceSwitch? msoComponentManager;
private static TraceSwitch? layoutPerformance;
private static TraceSwitch? layoutSuspendResume;
private static TraceSwitch? richLayout;
private static TraceSwitch? setBounds;

private static BooleanSwitch? lifetimeTracing;

private static TraceSwitch? s_handleLeak;
private static BooleanSwitch? s_traceCollect;
private static BooleanSwitch? s_commonDesignerServices;

public static TraceSwitch ActiveX
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using static Interop;

namespace System.Windows.Forms
Expand All @@ -18,7 +19,7 @@ public class FileDialogCustomPlace
private string _path = string.Empty;
private Guid _knownFolderGuid = Guid.Empty;

public FileDialogCustomPlace(string path)
public FileDialogCustomPlace(string? path)
{
Path = path;
}
Expand All @@ -28,6 +29,7 @@ public FileDialogCustomPlace(Guid knownFolderGuid)
KnownFolderGuid = knownFolderGuid;
}

[AllowNull]
public string Path
{
get => _path ?? string.Empty;
Expand Down Expand Up @@ -58,7 +60,7 @@ public override string ToString()
/// to an actual filesystem directory.
/// The caller is responsible for handling these situations.
/// </remarks>
internal FileDialogNative.IShellItem GetNativePath()
internal FileDialogNative.IShellItem? GetNativePath()
{
string filePathString;
if (!string.IsNullOrEmpty(_path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal void Apply(FileDialogNative.IFileDialog dialog)

try
{
FileDialogNative.IShellItem shellItem = customPlace.GetNativePath();
FileDialogNative.IShellItem? shellItem = customPlace.GetNativePath();
if (null != shellItem)
{
dialog.AddPlace(shellItem, 0);
Expand All @@ -32,7 +32,7 @@ internal void Apply(FileDialogNative.IFileDialog dialog)
}
}

public void Add(string path) => Add(new FileDialogCustomPlace(path));
public void Add(string? path) => Add(new FileDialogCustomPlace(path));

public void Add(Guid knownFolderGuid) => Add(new FileDialogCustomPlace(knownFolderGuid));
}
Expand Down
Loading