コード例 #1
0
        public static object CreateLocalServer(Guid clsid)
        {
            Utils.COSERVERINFO coserverinfo = default(Utils.COSERVERINFO);
            coserverinfo.pwszName    = null;
            coserverinfo.pAuthInfo   = IntPtr.Zero;
            coserverinfo.dwReserved1 = 0U;
            coserverinfo.dwReserved2 = 0U;
            GCHandle gchandle = GCHandle.Alloc(Utils.IID_IUnknown, GCHandleType.Pinned);

            Utils.MULTI_QI[] array = new Utils.MULTI_QI[1];
            array[0].iid  = gchandle.AddrOfPinnedObject();
            array[0].pItf = null;
            array[0].hr   = 0U;
            try
            {
                Utils.CoCreateInstanceEx(ref clsid, null, 5U, ref coserverinfo, 1U, array);
            }
            finally
            {
                gchandle.Free();
            }
            if (array[0].hr != 0U)
            {
                throw new ExternalException("CoCreateInstanceEx: 0x{0:X8}" + array[0].hr);
            }
            return(array[0].pItf);
        }
コード例 #2
0
 // Token: 0x060000AE RID: 174 RVA: 0x00002BE8 File Offset: 0x00000DE8
 public Utils.COSERVERINFO Allocate(string hostName, string username, string password, string domain)
 {
     Utils.COSERVERINFO result = default(Utils.COSERVERINFO);
     result.pwszName    = hostName;
     result.pAuthInfo   = IntPtr.Zero;
     result.dwReserved1 = 0U;
     result.dwReserved2 = 0U;
     if (string.IsNullOrEmpty(username))
     {
         return(result);
     }
     this.m_hUserName = GCHandle.Alloc(username, GCHandleType.Pinned);
     this.m_hPassword = GCHandle.Alloc(password, GCHandleType.Pinned);
     this.m_hDomain   = GCHandle.Alloc(domain, GCHandleType.Pinned);
     this.m_hIdentity = default(GCHandle);
     this.m_hIdentity = GCHandle.Alloc(new Utils.COAUTHIDENTITY
     {
         User           = this.m_hUserName.AddrOfPinnedObject(),
         UserLength     = (uint)((username != null) ? username.Length : 0),
         Password       = this.m_hPassword.AddrOfPinnedObject(),
         PasswordLength = (uint)((password != null) ? password.Length : 0),
         Domain         = this.m_hDomain.AddrOfPinnedObject(),
         DomainLength   = (uint)((domain != null) ? domain.Length : 0),
         Flags          = 2U
     }, GCHandleType.Pinned);
     this.m_hAuthInfo = GCHandle.Alloc(new Utils.COAUTHINFO
     {
         dwAuthnSvc           = 10U,
         dwAuthzSvc           = 0U,
         pwszServerPrincName  = IntPtr.Zero,
         dwAuthnLevel         = 2U,
         dwImpersonationLevel = 3U,
         pAuthIdentityData    = this.m_hIdentity.AddrOfPinnedObject(),
         dwCapabilities       = 0U
     }, GCHandleType.Pinned);
     result.pAuthInfo = this.m_hAuthInfo.AddrOfPinnedObject();
     return(result);
 }
コード例 #3
0
        public static object CreateInstance(Guid clsid, string hostName, string username, string password, string domain)
        {
            Utils.ServerInfo   serverInfo   = new Utils.ServerInfo();
            Utils.COSERVERINFO coserverinfo = serverInfo.Allocate(hostName, username, password, domain);
            GCHandle           gchandle     = GCHandle.Alloc(Utils.IID_IUnknown, GCHandleType.Pinned);

            Utils.MULTI_QI[] array = new Utils.MULTI_QI[1];
            array[0].iid  = gchandle.AddrOfPinnedObject();
            array[0].pItf = null;
            array[0].hr   = 0U;
            try
            {
                uint dwClsCtx = 5U;
                if (!string.IsNullOrEmpty(hostName) && hostName != "localhost")
                {
                    dwClsCtx = 20U;
                }
                Utils.CoCreateInstanceEx(ref clsid, null, dwClsCtx, ref coserverinfo, 1U, array);
            }
            finally
            {
                if (gchandle.IsAllocated)
                {
                    gchandle.Free();
                }
                serverInfo.Deallocate();
            }
            if (array[0].hr != 0U)
            {
                throw Utils.CreateComException(-2147467259, "Could not create COM server '{0}' on host '{1}'. Reason: {2}.", new object[]
                {
                    clsid,
                    hostName,
                    Utils.GetSystemMessage((int)array[0].hr, 2048)
                });
            }
            return(array[0].pItf);
        }
コード例 #4
0
 private static extern void CoGetClassObject([MarshalAs(UnmanagedType.LPStruct)] Guid clsid, uint dwClsContext, [In] ref Utils.COSERVERINFO pServerInfo, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
コード例 #5
0
 private static extern void CoCreateInstanceEx(ref Guid clsid, [MarshalAs(UnmanagedType.IUnknown)] object punkOuter, uint dwClsCtx, [In] ref Utils.COSERVERINFO pServerInfo, uint dwCount, [In][Out] Utils.MULTI_QI[] pResults);