/// <summary>
        ///  The DsrGetDcNameEx2 method returns information about
        ///  a domain controller in the specified domain and site. Supported
        ///  in windows_2000_server, windows_xp, windows_server_2003,
        ///  windows_vista, and windows_server_2008, windows_7,
        ///  and windows_server_7. The method will also verify that
        ///  the responding DC database contains an account if AccountName
        ///  is specified. The server that receives this call is
        ///  not required to be a DC. Opnum: 34 
        /// </summary>
        /// <param name="ComputerName">
        ///  The custom RPC binding handle (section ).
        /// </param>
        /// <param name="AccountName">
        ///  A null-terminated Unicode string that contains the name
        ///  of the account that MUST exist and be enabled on the
        ///  DC.
        /// </param>
        /// <param name="AllowableAccountControlBits">
        ///  A set of bit flags that list properties of the AccountName
        ///  account. A flag is TRUE (or set) if its value is equal
        ///  to 1. If the flag is set, then the account MUST have
        ///  that property; otherwise, the property is ignored.
        ///  The value is constructed from zero or more bit flags
        ///  from the following table.
        /// </param>
        /// <param name="DomainName">
        ///  A null-terminated Unicode string that contains the domain
        ///  name (3).
        /// </param>
        /// <param name="DomainGuid">
        ///  A pointer to a GUID structure that specifies the GUID
        ///  of the domain queried. If DomainGuid is not NULL and
        ///  the domain specified by DomainName cannot be found,
        ///  the DC locator attempts to locate a DC in the domain
        ///  that has the GUID specified by DomainGuid. This allows
        ///  renamed domains to be found by their GUID.
        /// </param>
        /// <param name="SiteName">
        ///  A null-terminated string that contains the name of the
        ///  site in which the DC MUST be located.
        /// </param>
        /// <param name="Flags">
        ///  A set of bit flags that provide additional data that
        ///  is used to process the request. A flag is TRUE (or
        ///  set) if its value is equal to 1. The value is constructed
        ///  from zero or more bit flags from the following table,
        ///  with the exceptions that bits D, E, and H cannot be
        ///  combined; S and R cannot be combined; and N and O cannot
        ///  be combined.
        /// </param>
        /// <param name="DomainControllerInfo">
        ///  A pointer to a DOMAIN_CONTROLLER_INFOW structure (section
        ///  ) containing data about the DC.
        /// </param>
        public NetApiStatus DsrGetDcNameEx2(
            string ComputerName,
            string AccountName,
            uint AllowableAccountControlBits,
            string DomainName,
            Guid? DomainGuid,
            string SiteName,
            uint Flags,
            out _DOMAIN_CONTROLLER_INFOW? DomainControllerInfo)
        {
            const ushort opnum = 34;

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

            SafeIntPtr pComputerName = Marshal.StringToHGlobalUni(ComputerName);
            SafeIntPtr pAccountName = Marshal.StringToHGlobalUni(AccountName);
            SafeIntPtr pDomainName = Marshal.StringToHGlobalUni(DomainName);
            SafeIntPtr pDomainGuid = TypeMarshal.ToIntPtr(DomainGuid);
            SafeIntPtr pSiteName = Marshal.StringToHGlobalUni(SiteName);

            paramList = new Int3264[] {
                pComputerName,
                pAccountName,
                AllowableAccountControlBits,
                pDomainName,
                pDomainGuid,
                pSiteName,
                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 pDomainControllerInfo = outParamList[7];
                pDomainControllerInfo = Marshal.ReadIntPtr(pDomainControllerInfo);
                DomainControllerInfo = TypeMarshal.ToNullableStruct<_DOMAIN_CONTROLLER_INFOW>(pDomainControllerInfo);

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

            pComputerName.Dispose();
            pAccountName.Dispose();
            pDomainName.Dispose();
            pDomainGuid.Dispose();
            pSiteName.Dispose();

            return (NetApiStatus)retVal;
        }
 /// <summary>
 ///  The DsrGetDcNameEx2 method returns information about
 ///  a domain controller in the specified domain and site. Supported
 ///  in windows_2000_server, windows_xp, windows_server_2003,
 ///  windows_vista, and windows_server_2008, windows_7,
 ///  and windows_server_7. The method will also verify that
 ///  the responding DC database contains an account if AccountName
 ///  is specified. The server that receives this call is
 ///  not required to be a DC. Opnum: 34 
 /// </summary>
 /// <param name="computerName">
 ///  The custom RPC binding handle.
 /// </param>
 /// <param name="accountName">
 ///  A null-terminated Unicode string that contains the name
 ///  of the account that MUST exist and be enabled on the
 ///  DC.
 /// </param>
 /// <param name="allowableAccountControlBits">
 ///  A set of bit flags that list properties of the AccountName
 ///  account. A flag is TRUE (or set) if its value is equal
 ///  to 1. If the flag is set, then the account MUST have
 ///  that property; otherwise, the property is ignored.
 ///  The value is constructed from zero or more bit flags
 ///  from the following table.
 /// </param>
 /// <param name="domainName">
 ///  A null-terminated Unicode string that contains the domain
 ///  name (3).
 /// </param>
 /// <param name="domainGuid">
 ///  A pointer to a GUID structure that specifies the GUID
 ///  of the domain queried. If DomainGuid is not NULL and
 ///  the domain specified by DomainName cannot be found,
 ///  the DC locator attempts to locate a DC in the domain
 ///  that has the GUID specified by DomainGuid. This allows
 ///  renamed domains to be found by their GUID.
 /// </param>
 /// <param name="siteName">
 ///  A null-terminated string that contains the name of the
 ///  site in which the DC MUST be located.
 /// </param>
 /// <param name="flags">
 ///  A set of bit flags that provide additional data that
 ///  is used to process the request. A flag is TRUE (or
 ///  set) if its value is equal to 1. The value is constructed
 ///  from zero or more bit flags from the following table,
 ///  with the exceptions that bits D, E, and H cannot be
 ///  combined; S and R cannot be combined; and N and O cannot
 ///  be combined.
 /// </param>
 /// <param name="domainControllerInfo">
 ///  A pointer to a DOMAIN_CONTROLLER_INFOW structure 
 ///  containing data about the DC.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus DsrGetDcNameEx2(
     string computerName,
     string accountName,
     NrpcAllowableAccountControlBits allowableAccountControlBits,
     string domainName,
     Guid? domainGuid,
     string siteName,
     NrpcDsrGetDcNameFlags flags,
     out _DOMAIN_CONTROLLER_INFOW? domainControllerInfo)
 {
     return rpc.DsrGetDcNameEx2(
         computerName,
         accountName,
         (uint)allowableAccountControlBits,
         domainName,
         domainGuid,
         siteName,
         (uint)flags,
         out domainControllerInfo);
 }
        /// <summary>
        ///  The DsrGetDcNameEx method Supported in windows_2000_server,
        ///  windows_xp, windows_server_2003, windows_vista, windows_server_2008,
        ///  windows_7, and windows_server_7. is a predecessor to
        ///  the DsrGetDcNameEx2 method. The method returns information
        ///  about a domain controller in the specified domain and
        ///  site. All parameters of this method have the same meanings
        ///  as the identically named parameters of the DsrGetDcNameEx2
        ///  method. Opnum: 27 
        /// </summary>
        /// <param name="ComputerName">
        ///  ComputerName parameter.
        /// </param>
        /// <param name="DomainName">
        ///  DomainName parameter.
        /// </param>
        /// <param name="DomainGuid">
        ///  DomainGuid parameter.
        /// </param>
        /// <param name="SiteName">
        ///  SiteName parameter.
        /// </param>
        /// <param name="Flags">
        ///  Flags parameter.
        /// </param>
        /// <param name="DomainControllerInfo">
        ///  DomainControllerInfo parameter.
        /// </param>
        public NetApiStatus DsrGetDcNameEx(
            string ComputerName,
            string DomainName,
            Guid? DomainGuid,
            string SiteName,
            uint Flags,
            out _DOMAIN_CONTROLLER_INFOW? DomainControllerInfo)
        {
            const ushort opnum = 27;

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

            //CLIENT_CALL_RETURN _RetVal;
            //_RetVal = NdrClientCall2(
            //return ( NET_API_STATUS  )_RetVal.Simple;

            SafeIntPtr pComputerName = Marshal.StringToHGlobalUni(ComputerName);
            SafeIntPtr pDomainName = Marshal.StringToHGlobalUni(DomainName);
            SafeIntPtr pDomainGuid = TypeMarshal.ToIntPtr(DomainGuid);
            SafeIntPtr pSiteName = Marshal.StringToHGlobalUni(SiteName);

            paramList = new Int3264[] {
                pComputerName,
                pDomainName,
                pDomainGuid,
                pSiteName,
                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))
            {
                //DomainControllerInfo is double pointer (**)
                //pDomainControllerInfo won't be null, read pointer inside directly.
                IntPtr pDomainControllerInfo;
                pDomainControllerInfo = outParamList[5];
                pDomainControllerInfo = Marshal.ReadIntPtr(pDomainControllerInfo);
                DomainControllerInfo = TypeMarshal.ToNullableStruct<_DOMAIN_CONTROLLER_INFOW>(pDomainControllerInfo);

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

            pComputerName.Dispose();
            pDomainName.Dispose();
            pDomainGuid.Dispose();
            pSiteName.Dispose();

            return (NetApiStatus)retVal;
        }
 /// <summary>
 ///  The DsrGetDcNameEx method Supported in windows_2000_server,
 ///  windows_xp, windows_server_2003, windows_vista, windows_server_2008,
 ///  windows_7, and windows_server_7. is a predecessor to
 ///  the DsrGetDcNameEx2 method. The method returns information
 ///  about a domain controller in the specified domain and
 ///  site. All parameters of this method have the same meanings
 ///  as the identically named parameters of the DsrGetDcNameEx2
 ///  method. Opnum: 27 
 /// </summary>
 /// <param name="computerName">
 ///  ComputerName parameter.
 /// </param>
 /// <param name="domainName">
 ///  DomainName parameter.
 /// </param>
 /// <param name="domainGuid">
 ///  DomainGuid parameter.
 /// </param>
 /// <param name="siteName">
 ///  SiteName parameter.
 /// </param>
 /// <param name="flags">
 ///  Flags parameter.
 /// </param>
 /// <param name="domainControllerInfo">
 ///  DomainControllerInfo parameter.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus DsrGetDcNameEx(
     string computerName,
     string domainName,
     Guid? domainGuid,
     string siteName,
     NrpcDsrGetDcNameFlags flags,
     out _DOMAIN_CONTROLLER_INFOW? domainControllerInfo)
 {
     return rpc.DsrGetDcNameEx(
         computerName,
         domainName,
         domainGuid,
         siteName,
         (uint)flags,
         out domainControllerInfo);
 }