mirror of https://github.com/dahall/Vanara.git
Fixed bug in marshaler for LSA_UNICODE_STRING under X64 that caused alignment error and failure on all calls. Thanks @ryannewington for identifying the problem and where to fix it (#169).
parent
bde637b8d3
commit
da963a8115
|
@ -3288,18 +3288,14 @@ namespace Vanara.PInvoke
|
||||||
internal static IntPtr MarshalValue(string value)
|
internal static IntPtr MarshalValue(string value)
|
||||||
{
|
{
|
||||||
if (value is null) return IntPtr.Zero;
|
if (value is null) return IntPtr.Zero;
|
||||||
var length = (short)StringHelper.GetByteCount(value, false, CharSet.Unicode);
|
var lus = new LSA_UNICODE_STRING { length = (ushort)StringHelper.GetByteCount(value, false, CharSet.Unicode) };
|
||||||
var chSz = StringHelper.GetCharSize(CharSet.Unicode);
|
var chSz = StringHelper.GetCharSize(CharSet.Unicode);
|
||||||
var maxLength = (short)(length + chSz);
|
lus.MaximumLength = (ushort)(lus.length + chSz);
|
||||||
var sz = 4 + IntPtr.Size + length + chSz;
|
var ssz = Marshal.SizeOf(typeof(LSA_UNICODE_STRING));
|
||||||
var mem = Marshal.AllocCoTaskMem(sz);
|
var mem = Marshal.AllocCoTaskMem(ssz + lus.MaximumLength);
|
||||||
using (var s = new NativeMemoryStream(mem, sz, System.IO.FileAccess.Write) { CharSet = CharSet.Unicode })
|
lus.Buffer = mem.Offset(ssz);
|
||||||
{
|
mem.Write(lus);
|
||||||
s.Write(length);
|
StringHelper.Write(value, mem.Offset(ssz), out _, true, CharSet.Unicode, lus.MaximumLength);
|
||||||
s.Write(maxLength);
|
|
||||||
s.WriteReference(value);
|
|
||||||
s.Flush();
|
|
||||||
}
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue