mirror of https://github.com/dahall/Vanara.git
Fixed CallMethodWithTypedBuf to only set value on success.
parent
4143c8767e
commit
31775c94f0
|
@ -112,13 +112,15 @@ namespace Vanara.PInvoke
|
||||||
if (err.Failed && (bufErr == null || bufErr.Value != err) && !buffErrs.Contains(err)) return err;
|
if (err.Failed && (bufErr == null || bufErr.Value != err) && !buffErrs.Contains(err)) return err;
|
||||||
using (var buf = new SafeHGlobalHandle(sz.ToInt32(null)))
|
using (var buf = new SafeHGlobalHandle(sz.ToInt32(null)))
|
||||||
{
|
{
|
||||||
var ret = method(buf.DangerousGetHandle(), ref sz);
|
err = method(buf.DangerousGetHandle(), ref sz);
|
||||||
|
if (err.Succeeded)
|
||||||
result = (outConverter ?? Conv)(buf.DangerousGetHandle(), sz);
|
result = (outConverter ?? Conv)(buf.DangerousGetHandle(), sz);
|
||||||
return ret;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Error GetSize(ref TSize sz1) => method(IntPtr.Zero, ref sz1);
|
Win32Error GetSize(ref TSize sz1) => method(IntPtr.Zero, ref sz1);
|
||||||
TOut Conv(IntPtr p, TSize s) => p.ToStructure<TOut>();
|
|
||||||
|
static TOut Conv(IntPtr p, TSize s) => p == IntPtr.Zero ? default : p.Convert<TOut>(Convert.ToUInt32(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Calls a method with buffer for a type and gets the result or error.</summary>
|
/// <summary>Calls a method with buffer for a type and gets the result or error.</summary>
|
||||||
|
|
Loading…
Reference in New Issue