/// <summary>
 ///  The NetrEnumerateTrustedDomainsEx methodSupported in
 ///  windows_2000_server, windows_xp, windows_server_2003,
 ///  windows_vista, windows_server_2008, windows_7, and
 ///  windows_server_7. returns a list of trusted domains
 ///  from a specified server. This method extends NetrEnumerateTrustedDomains
 ///  by returning an array of domains in a more flexible
 ///  DS_DOMAIN_TRUSTSW structure, 
 ///  rather than the array of strings in DOMAIN_NAME_BUFFER
 ///  structure. The array is returned
 ///  as part of the NETLOGON_TRUSTED_DOMAIN_ARRAY structure.
 ///  Opnum: 36 
 /// </summary>
 /// <param name="serverName">
 ///  The custom RPC binding handle.
 /// </param>
 /// <param name="domains">
 ///  A pointer to a NETLOGON_TRUSTED_DOMAIN_ARRAY structure,
 ///  that contains an array of
 ///  DS_DOMAIN_TRUSTSW structures, one for each trusted domain.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus NetrEnumerateTrustedDomainsEx(
     string serverName,
     out _NETLOGON_TRUSTED_DOMAIN_ARRAY? domains)
 {
     return rpc.NetrEnumerateTrustedDomainsEx(
         serverName,
         out domains);
 }
        /// <summary>
        ///  The DsrEnumerateDomainTrusts method Supported in windows_2000_server,
        ///  windows_xp, windows_server_2003, windows_vista, windows_server_2008,
        ///  windows_7, and windows_server_7. returns an enumerated
        ///  list of domain trusts, filtered by a set of flags, from
        ///  the specified server. Opnum: 40 
        /// </summary>
        /// <param name="ServerName">
        ///  The custom RPC binding handle, as specified in section
        ///  .
        /// </param>
        /// <param name="Flags">
        ///  A set of bit flags that specify properties that MUST
        ///  be true for a domain trust to be part of the returned
        ///  domain name list. A flag is TRUE (or set) if its value
        ///  is equal to 1. Flags MUST contain one or more of the
        ///  following bits.
        /// </param>
        /// <param name="Domains">
        ///  A pointer to a NETLOGON_TRUSTED_DOMAIN_ARRAY structure,
        ///  as specified in section , that contains a list of trusted
        ///  domains.
        /// </param>
        public NetApiStatus DsrEnumerateDomainTrusts(
            string ServerName,
            uint Flags,
            out _NETLOGON_TRUSTED_DOMAIN_ARRAY? Domains)
        {
            const ushort opnum = 40;

            byte[] requestStub;
            byte[] responseStub;
            Int3264[] paramList;
            int retVal;

            SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName);

            paramList = new Int3264[] {
                pServerName,
                Flags,
                IntPtr.Zero,
                0 // retVal
            };

            requestStub = RpceStubEncoder.ToBytes(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    paramList);

            rpceClientTransport.Call(opnum, requestStub, rpceTimeout, out responseStub);

            using (RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    responseStub,
                    paramList))
            {
                IntPtr pDomains = outParamList[2];
                Domains = TypeMarshal.ToNullableStruct<_NETLOGON_TRUSTED_DOMAIN_ARRAY>(pDomains);

                retVal = outParamList[3].ToInt32();
            }

            pServerName.Dispose();

            return (NetApiStatus)retVal;
        }
 /// <summary>
 ///  The DsrEnumerateDomainTrusts method Supported in windows_2000_server,
 ///  windows_xp, windows_server_2003, windows_vista, windows_server_2008,
 ///  windows_7, and windows_server_7. returns an enumerated
 ///  list of domain trusts, filtered by a set of flags, from
 ///  the specified server. Opnum: 40 
 /// </summary>
 /// <param name="serverName">
 ///  The custom RPC binding handle.
 /// </param>
 /// <param name="flags">
 ///  A set of bit flags that specify properties that MUST
 ///  be true for a domain trust to be part of the returned
 ///  domain name list. A flag is TRUE (or set) if its value
 ///  is equal to 1. Flags MUST contain one or more of the
 ///  following bits.
 /// </param>
 /// <param name="domains">
 ///  A pointer to a NETLOGON_TRUSTED_DOMAIN_ARRAY structure,
 ///  that contains a list of trusted
 ///  domains.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus DsrEnumerateDomainTrusts(
     string serverName,
     NrpcDsrEnumerateDomainTrustsFlags flags,
     out _NETLOGON_TRUSTED_DOMAIN_ARRAY? domains)
 {
     return rpc.DsrEnumerateDomainTrusts(
         serverName,
         (uint)flags,
         out domains);
 }