/// <summary>
 ///  The SamrEnumerateDomainsInSamServer method obtains a
 ///  listing of all domains hosted by the server side of
 ///  this protocol. Opnum: 6 
 /// </summary>
 /// <param name="ServerHandle">
 ///  An RPC context handle, as specified in section , representing
 ///  a server object.
 /// </param>
 /// <param name="EnumerationContext">
 ///  This value is a cookie that the server can use to continue
 ///  an enumeration on a subsequent call. It is an opaque
 ///  value to the client.
 /// </param>
 /// <param name="Buffer">
 ///  A listing of domain information, as described in section
 ///  .
 /// </param>
 /// <param name="PreferedMaximumLength">
 ///  The requested maximum number of bytes to return in Buffer.
 /// </param>
 /// <param name="CountReturned">
 ///  The count of domain elements returned in Buffer.
 /// </param>
 /// <returns>
 /// status of the function call, for example: 0 indicates STATUS_SUCCESS
 /// </returns>
 public int SamrEnumerateDomainsInSamServer(System.IntPtr ServerHandle,
     ref System.UInt32? EnumerationContext,
     out _SAMPR_ENUMERATION_BUFFER? Buffer,
     uint PreferedMaximumLength,
     out System.UInt32 CountReturned)
 {
     return rpc.SamrEnumerateDomainsInSamServer(ServerHandle,
         ref EnumerationContext, out Buffer, PreferedMaximumLength, out CountReturned);
 }
 /// <summary>
 ///  The SamrEnumerateUsersInDomain method enumerates all
 ///  users. Opnum: 13 
 /// </summary>
 /// <param name="DomainHandle">
 ///  An RPC context handle, as specified in section , representing
 ///  a domain object.
 /// </param>
 /// <param name="EnumerationContext">
 ///  This value is a cookie that the server can use to continue
 ///  an enumeration on a subsequent call. It is an opaque
 ///  value to the client.
 /// </param>
 /// <param name="UserAccountControl">
 ///  A filter value to be used on the userAccountControl
 ///  attribute.
 /// </param>
 /// <param name="Buffer">
 ///  A list of user information, as specified in section
 ///  .
 /// </param>
 /// <param name="PreferedMaximumLength">
 ///  The requested maximum number of bytes to return in Buffer.
 /// </param>
 /// <param name="CountReturned">
 ///  The count of domain elements returned in Buffer.
 /// </param>
 /// <returns>
 /// status of the function call, for example: 0 indicates STATUS_SUCCESS
 /// </returns>
 public int SamrEnumerateUsersInDomain(System.IntPtr DomainHandle,
     ref System.UInt32? EnumerationContext,
     uint UserAccountControl,
     out _SAMPR_ENUMERATION_BUFFER? Buffer,
     uint PreferedMaximumLength,
     out System.UInt32 CountReturned)
 {
     return rpc.SamrEnumerateUsersInDomain(DomainHandle,
         ref EnumerationContext, UserAccountControl, out Buffer, PreferedMaximumLength, out CountReturned);
 }
        /// <summary>
        ///  The SamrEnumerateUsersInDomain method enumerates all
        ///  users. Opnum: 13 
        /// </summary>
        /// <param name="DomainHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a domain object.
        /// </param>
        /// <param name="EnumerationContext">
        ///  This value is a cookie that the server can use to continue
        ///  an enumeration on a subsequent call. It is an opaque
        ///  value to the client.
        /// </param>
        /// <param name="UserAccountControl">
        ///  A filter value to be used on the userAccountControl
        ///  attribute.
        /// </param>
        /// <param name="Buffer">
        ///  A list of user information, as specified in section
        ///  .
        /// </param>
        /// <param name="PreferedMaximumLength">
        ///  The requested maximum number of bytes to return in Buffer.
        /// </param>
        /// <param name="CountReturned">
        ///  The count of domain elements returned in Buffer.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrEnumerateUsersInDomain(
            IntPtr DomainHandle,
            ref uint? EnumerationContext,
            uint UserAccountControl,
            out _SAMPR_ENUMERATION_BUFFER? Buffer,
            uint PreferedMaximumLength,
            out uint CountReturned)
        {
            const ushort opnum = 13;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pEnumerationContext = TypeMarshal.ToIntPtr(EnumerationContext);

            paramList = new Int3264[] {
                DomainHandle,
                pEnumerationContext,
                UserAccountControl,
                IntPtr.Zero,
                PreferedMaximumLength,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    EnumerationContext = TypeMarshal.ToNullableStruct<uint>(outParamList[1]);
                    Buffer = TypeMarshal.ToNullableStruct<_SAMPR_ENUMERATION_BUFFER>(
                        Marshal.ReadIntPtr(outParamList[3]));
                    CountReturned = TypeMarshal.ToStruct<uint>(outParamList[5]);
                    retVal = outParamList[6].ToInt32();
                }
            }
            finally
            {
                pEnumerationContext.Dispose();
            }

            return retVal;
        }