WinFormsComInterop icon indicating copy to clipboard operation
WinFormsComInterop copied to clipboard

Check for return value after call in out parameters

Open kant2002 opened this issue 4 years ago • 0 comments

HRESULT Shell32.IFileOpenDialog.GetSelectedItems(out Shell32.IShellItemArray ppsai)
{
    var comDispatch = (System.IntPtr*)thisPtr;
    var vtbl = (System.IntPtr*)comDispatch[0];
    System.IntPtr local_0;
    int retVal;
    retVal = ((delegate* unmanaged<System.IntPtr, System.IntPtr*, int>)vtbl[28])(thisPtr, &local_0);
    ppsai = local_0 == System.IntPtr.Zero ? null : (Shell32.IShellItemArray)Marshal.GetObjectForIUnknown(local_0);
    return (HRESULT)retVal;
}

retVal should be checked before calling Marshal.GetObjectForIUnknown

kant2002 avatar Jul 19 '21 14:07 kant2002