public MemoryRegion GetAuthData()
        {
            MemoryAlloc data;
            int         dataSize;
            int         domainNameOffset;
            int         userNameOffset;
            int         passwordOffset;
            string      lDomainName = _domainName != null ? _domainName : "";
            string      lUserName   = _userName != null ? _userName : "";
            string      lPassword   = _password != null ? _password : "";

            // The structure plus the strings must be stored in the same buffer,
            // so we have to do some computation.

            domainNameOffset = Marshal.SizeOf(typeof(Msv1_0_InteractiveLogon));
            userNameOffset   = domainNameOffset + lDomainName.Length * 2;
            passwordOffset   = userNameOffset + lUserName.Length * 2;
            dataSize         = passwordOffset + lPassword.Length * 2;
            data             = new MemoryAlloc(dataSize);

            Msv1_0_InteractiveLogon info = new Msv1_0_InteractiveLogon();

            info.MessageType = Msv1_0_LogonSubmitType.Interactive;

            info.LogonDomainName.MaximumLength = info.LogonDomainName.Length = (ushort)(lDomainName.Length * 2);
            info.LogonDomainName.Buffer        = data.Memory.Increment(domainNameOffset);
            data.WriteUnicodeString(domainNameOffset, lDomainName);

            info.UserName.MaximumLength = info.UserName.Length = (ushort)(lUserName.Length * 2);
            info.UserName.Buffer        = data.Memory.Increment(userNameOffset);
            data.WriteUnicodeString(userNameOffset, lUserName);

            info.Password.MaximumLength = info.Password.Length = (ushort)(lPassword.Length * 2);
            info.Password.Buffer        = data.Memory.Increment(passwordOffset);
            data.WriteUnicodeString(passwordOffset, lPassword);

            data.WriteStruct <Msv1_0_InteractiveLogon>(info);

            return(data);
        }
        public void ReadAuthData(MemoryRegion buffer)
        {
            Msv1_0_InteractiveLogon info = buffer.ReadStruct <Msv1_0_InteractiveLogon>();

            // Fix up relative addresses.
            if (info.LogonDomainName.Buffer.CompareTo(buffer.Size) < 0)
            {
                info.LogonDomainName.Buffer = info.LogonDomainName.Buffer.Increment(buffer);
            }
            if (info.UserName.Buffer.CompareTo(buffer.Size) < 0)
            {
                info.UserName.Buffer = info.UserName.Buffer.Increment(buffer);
            }
            if (info.Password.Buffer.CompareTo(buffer.Size) < 0)
            {
                info.Password.Buffer = info.Password.Buffer.Increment(buffer);
            }

            _domainName = info.LogonDomainName.Text;
            _userName   = info.UserName.Text;
            _password   = info.Password.Text;
        }
        public MemoryRegion GetAuthData()
        {
            string lDomainName = !string.IsNullOrEmpty(_domainName) ? _domainName : string.Empty;
            string lUserName   = !string.IsNullOrEmpty(_userName) ? _userName : string.Empty;
            string lPassword   = !string.IsNullOrEmpty(_password) ? _password : string.Empty;

            // The structure plus the strings must be stored in the same buffer,
            // so we have to do some computation.

            int domainNameOffset = Msv1_0_InteractiveLogon.SizeOf;
            int userNameOffset   = domainNameOffset + lDomainName.Length * 2;
            int passwordOffset   = userNameOffset + lUserName.Length * 2;
            int dataSize         = passwordOffset + lPassword.Length * 2;

            MemoryAlloc data = new MemoryAlloc(dataSize);

            Msv1_0_InteractiveLogon info = new Msv1_0_InteractiveLogon
            {
                MessageType = Msv1_0_LogonSubmitType.Interactive
            };

            info.LogonDomainName.MaximumLength = info.LogonDomainName.Length = (ushort)(lDomainName.Length * 2);
            info.LogonDomainName.Buffer        = data.Memory.Increment(domainNameOffset);
            data.WriteUnicodeString(domainNameOffset, lDomainName);

            info.UserName.MaximumLength = info.UserName.Length = (ushort)(lUserName.Length * 2);
            info.UserName.Buffer        = data.Memory.Increment(userNameOffset);
            data.WriteUnicodeString(userNameOffset, lUserName);

            info.Password.MaximumLength = info.Password.Length = (ushort)(lPassword.Length * 2);
            info.Password.Buffer        = data.Memory.Increment(passwordOffset);
            data.WriteUnicodeString(passwordOffset, lPassword);

            data.WriteStruct(info);

            return(data);
        }