mirror of https://github.com/dahall/Vanara.git
More SendMessage work
parent
eefe24a771
commit
a8730903e3
|
@ -3104,10 +3104,35 @@ namespace Vanara.PInvoke
|
|||
|
||||
private static IntPtr SendMessage<TLP>(HWND hWnd, uint msg, IntPtr wParam, ref TLP lParam)
|
||||
{
|
||||
using var lmem = SafeCoTaskMemHandle.CreateFromStructure(lParam);
|
||||
var lret = SendMessage(hWnd, msg, wParam, lmem);
|
||||
lParam = lmem.ToStructure<TLP>();
|
||||
return lret;
|
||||
// If this must mbe manually marshaled, do it
|
||||
if (typeof(IVanaraMarshaler).IsAssignableFrom(typeof(TLP)))
|
||||
return ManualMarshalSM(hWnd, msg, wParam, ref lParam);
|
||||
|
||||
// Try to pin first as this is most efficient.
|
||||
// This will fail just like checking for blit-ability, so take the hit once.
|
||||
try
|
||||
{
|
||||
using var lpin = new PinnedObject(lParam);
|
||||
return SendMessage(hWnd, msg, wParam, lpin);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// If not blitable, manually marshal
|
||||
return ManualMarshalSM(hWnd, msg, wParam, ref lParam);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// For all other exceptions, throw error.
|
||||
throw;
|
||||
}
|
||||
|
||||
static IntPtr ManualMarshalSM(HWND hWnd, uint msg, IntPtr wParam, ref TLP lParam)
|
||||
{
|
||||
using var lmem = SafeCoTaskMemHandle.CreateFromStructure(lParam);
|
||||
var lret = SendMessage(hWnd, msg, wParam, lmem);
|
||||
lParam = lmem.ToStructure<TLP>();
|
||||
return lret;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue