private static LSA_UNICODE_STRING InitLsaString(string s)
{
if (string.IsNullOrEmpty(s))
return new LSA_UNICODE_STRING();
// Unicode strings max. 32KB
if (s.Length > 0x7ffe)
throw new ArgumentException("String too long");
LSA_UNICODE_STRING lus = new LSA_UNICODE_STRING();
lus.Buffer = Marshal.StringToHGlobalUni(s);
lus.Length = (UInt16)(s.Length * UnicodeEncoding.CharSize);
lus.MaximumLength = (UInt16)((s.Length + 1) * UnicodeEncoding.CharSize);
return lus;
}