当前位置: 首页>>代码示例>>C#>>正文


C# ServerInfo.Deallocate方法代码示例

本文整理汇总了C#中ServerInfo.Deallocate方法的典型用法代码示例。如果您正苦于以下问题:C# ServerInfo.Deallocate方法的具体用法?C# ServerInfo.Deallocate怎么用?C# ServerInfo.Deallocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServerInfo的用法示例。


在下文中一共展示了ServerInfo.Deallocate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateInstance2

		/// <summary>
		/// Creates an instance of a COM server using the specified license key.
		/// </summary>
		public static object CreateInstance2(Guid clsid, string hostName, UserIdentity identity)
		{
            // validate the host name before proceeding (exception thrown if host is not valid).
            bool isLocalHost = IsLocalHost(hostName);

            // allocate the connection info.
			ServerInfo    serverInfo   = new ServerInfo();
			COSERVERINFO  coserverInfo = serverInfo.Allocate(hostName, identity);
			object        instance     = null; 
			IClassFactory factory      = null; 
			
			try
			{
                // create the factory.
                object unknown = null;

				CoGetClassObject(
					clsid,
					(isLocalHost)?CLSCTX_LOCAL_SERVER:CLSCTX_REMOTE_SERVER,
					ref coserverInfo,
					IID_IUnknown,
					out unknown);

                // SetProxySecurity(unknown, coserverInfo.pAuthInfo);
                
                factory = (IClassFactory)unknown;

                // check for valid factory.
                if (factory == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadCommunicationError, "Could not load IClassFactory for COM server '{0}' on host '{1}'.", clsid, hostName);
                }

                // SetProxySecurity(factory, coserverInfo.pAuthInfo);

			    factory.CreateInstance(null, IID_IUnknown, out instance);

                // SetProxySecurity(instance, coserverInfo.pAuthInfo);
			}
			finally
			{
				serverInfo.Deallocate();
			}

            return instance;
		}	
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:49,代码来源:ComUtils.cs

示例2: CreateInstanceWithLicenseKey

		/// <summary>
		/// Creates an instance of a COM server using the specified license key.
		/// </summary>
		public static object CreateInstanceWithLicenseKey(Guid clsid, string hostName, UserIdentity identity, string licenseKey)
		{
			ServerInfo     serverInfo   = new ServerInfo();
			COSERVERINFO   coserverInfo = serverInfo.Allocate(hostName, identity);
			object         instance     = null; 
			IClassFactory2 factory      = null; 

			try
			{
				// check whether connecting locally or remotely.
				uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER;

				if (hostName != null && hostName.Length > 0)
				{
					clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER;
				}

				// get the class factory.
				object unknown = null;

				CoGetClassObject(
					clsid,
					clsctx,
					ref coserverInfo,
					typeof(IClassFactory2).GUID,
					out unknown);

                // SetProxySecurity(unknown, coserverInfo.pAuthInfo);
                
                factory = (IClassFactory2)unknown;

                // check for valid factory.
                if (factory == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadCommunicationError, "Could not load IClassFactory2 for COM server '{0}' on host '{1}'.", clsid, hostName);
                }

                // SetProxySecurity(factory, coserverInfo.pAuthInfo);

				// create instance.
				factory.CreateInstanceLic(
					null,
					null,
					IID_IUnknown,
					licenseKey,
                    out instance);

                // SetProxySecurity(instance, coserverInfo.pAuthInfo);
			}
			finally
			{
				serverInfo.Deallocate();
                ComUtils.ReleaseServer(factory);
			}
			  
			return instance;
		}	
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:60,代码来源:ComUtils.cs

示例3: CreateInstance1

		/// <summary>
		/// Creates an instance of a COM server.
		/// </summary>
        public static object CreateInstance1(Guid clsid, string hostName, UserIdentity identity)
		{
			ServerInfo   serverInfo   = new ServerInfo();
			COSERVERINFO coserverInfo = serverInfo.Allocate(hostName, identity);

			GCHandle hIID = GCHandle.Alloc(IID_IUnknown, GCHandleType.Pinned);

			MULTI_QI[] results = new MULTI_QI[1];

			results[0].iid  = hIID.AddrOfPinnedObject();
			results[0].pItf = null;
			results[0].hr   = 0;

			try
			{
				// check whether connecting locally or remotely.
				uint clsctx = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER;

				if (!String.IsNullOrEmpty(hostName) && hostName != "localhost")
				{
					clsctx = CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER;
				}

				// create an instance.
				CoCreateInstanceEx(
					ref clsid,
					null,
					clsctx,
					ref coserverInfo,
					1,
					results);
			}
			finally
			{
				if (hIID.IsAllocated) hIID.Free();
				serverInfo.Deallocate();
			}

			if (results[0].hr != 0)
			{
                throw ServiceResultException.Create(
                    StatusCodes.BadCommunicationError, 
                    "Could not create COM server '{0}' on host '{1}'. Reason: {2}.", clsid, hostName, 
                    GetSystemMessage((int)results[0].hr, LOCALE_SYSTEM_DEFAULT));
			}

			return results[0].pItf;
		}
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:51,代码来源:ComUtils.cs


注:本文中的ServerInfo.Deallocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。