Skip to content

Commit

Permalink
Fix null references in DragDataObject
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJoeFin committed Nov 23, 2023
1 parent 3861317 commit cb3580e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Text-Grab/Models/DragDataObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public static IDataObject FromFile(string filePath)

public static void SetDragImage(this IDataObject dataObject, IntPtr hBitmap, int width, int height)
{
if (dataObject == null)
{
throw new ArgumentNullException(nameof(dataObject));
}
ArgumentNullException.ThrowIfNull(dataObject);

IDragSourceHelper dragDropHelper = (IDragSourceHelper)new DragDropHelper();
ShDragImage dragImage = new ShDragImage
Expand All @@ -37,14 +34,14 @@ public static void SetDragImage(this IDataObject dataObject, IntPtr hBitmap, int
}

[DllImport("shell32", CharSet = CharSet.Unicode)]
private static extern int SHCreateItemFromParsingName(string path, IBindCtx pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IShellItem ppv);
private static extern int SHCreateItemFromParsingName(string path, IBindCtx? pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IShellItem ppv);

[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItem
{
[PreserveSig]
int BindToHandler(IBindCtx pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid bhid, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
int BindToHandler(IBindCtx? pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid bhid, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);

// more methods available, but we don't need them
}
Expand Down

0 comments on commit cb3580e

Please sign in to comment.