《.net反射调用COM组件并释放资源》由会员分享,可在线阅读,更多相关《.net反射调用COM组件并释放资源(2页珍藏版)》请在金锄头文库上搜索。
1、using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Web;namespace JianShuo.O2OMobileClient.O2ODefault.Modelsstatic public class GetActiveXObjecterstatic public void GetActiveXObject(object obje, int oute, string MonthsName, out object retun)retun = ne
2、w objectoute;Type comType = null;object comObj = null;tryGuid b2b = new Guid(D858B0E9-9AB9-4E67-B979-50AFD07A115A);comType = Type.GetTypeFromCLSID(b2b);/获取CLSIDcomObj = Activator.CreateInstance(comType);/转换成类Object paras = obje;ParameterModifier de = new ParameterModifier1;de0 = new ParameterModifie
3、r(obje.Length);if (oute 0)for (int i = obje.Length-1; i obje.Length - oute-1; i-)de0i = true;/设置out输出相comType.InvokeMember(MonthsName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.InvokeMethod, null, comObj, paras, de, null, null);/调用COM接口方法int count = 0;for (int i = obje.Length - oute; i obje.Length; i+)retuncount = objei;count+; catch (Exception ex)retunoute = ex.Message;finallycomObj = null;comType = null;GC.Collect();/释放资源