/// <summary> /// Obtiene el formulario para que pueda ser utilizado en toda la clase /// </summary> /// <param name="formUID"></param> public void obtenerFormulario(string formUID, string ruta) { try { //Obtiene el formulario de Visualizar XML visualiza = SAPbouiCOM.Framework.Application.SBO_Application.Forms.Item("frmVisualizar"); //Agrega el objeto Browser de tipo ActiveX en el formulario Item oItem = visualiza.Items.Add("Brwsr", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X); oItem.Height = visualiza.Height - 37; oItem.Width = visualiza.Width - 15; ActiveX axBrwsr = (ActiveX)oItem.Specific; //Se define la clase para el objeto ActiveX axBrwsr.ClassID = "Shell.Explorer.2"; //Se crea el visor de Internet Explorer oSHDocVw = ((SHDocVw.InternetExplorer)(axBrwsr.Object)); //Se carga el archivo xml al visor oSHDocVw.Navigate(ruta, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //Se borra el archivo cargado File.Delete(ruta); } catch (Exception ex) { SAPbouiCOM.Framework.Application.SBO_Application.MessageBox("ObtenerFormulario/Error:" + ex.ToString()); } }
protected bool TypeIsGoodEnough(Type type) { bool isGood = false; if (type != null) { // If this is the generic COM wrapper type, then its not // good enough if (!ActiveX.TypeEqualsComRoot(type) && !ReflectionHelper.TypeEqualsObject(type)) { isGood = true; } } if (TraceUtil.If(this, TraceLevel.Info)) { Trace.WriteLine("ComObjInfo - good enough: " + type + " " + isGood); } return(isGood); }
public static int GetRunningObjectCount() { int count = 0; UCOMIBindCtx bc; UCOMIRunningObjectTable rot; UCOMIEnumMoniker em; UCOMIMoniker[] moniker = new UCOMIMoniker[1]; int unused; ActiveX.CreateBindCtx(0, out bc); bc.GetRunningObjectTable(out rot); rot.EnumRunning(out em); while (0 == em.Next(1, moniker, out unused)) { count++; } Marshal.ReleaseComObject(bc); Marshal.ReleaseComObject(rot); Marshal.ReleaseComObject(em); return(count); }
// This is used for the case of a class outside of a type // libarary protected Type GetTypeForClass() { Type type = null; // See if we have type lib information from the registry if (_typeLibString != null) { return(GetTypeFromTypeLib (TypeLibrary.GetTypeLib(new Guid(_typeLibString), _typeLibVersion))); } // Have to try and create the object and get the type lib // information from the created object if (TraceUtil.If(this, TraceLevel.Info)) { TraceUtil.WriteLineInfo(this, "Attempting to create obj for: " + this); } IntPtr comObj; int result = ActiveX.CoCreateInstance(ref _guid, (IntPtr)0, ActiveX.CLSCTX_SERVER, ref ActiveX.IUnknownIID, out comObj); if (result == 0) { ComObjectInfo objInfo = null; try { // Wrap our object info stuff and get the type objInfo = new ComObjectInfo(comObj); type = GetTypeFromTypeLib(objInfo.TypeLib); } catch (Exception ex) { _typeFailedException = new Exception("Unable to determine CLR type for " + GetName(), ex); throw _typeFailedException; } finally { try { // Clean up the object info, if we made it that // far if (objInfo != null) { Object o = objInfo.Obj; ObjectInfo.RemoveObjectInfo(o); while (true) { int count = Marshal.ReleaseComObject(o); TraceUtil.WriteLineInfo (this, "final Marshal.ReleaseComObject count: " + count); if (count <= 0) { break; } } } while (true) { int count = Marshal.Release(comObj); TraceUtil.WriteLineInfo (this, "final Marshal.Release count: " + count); if (count <= 0) { break; } } } catch (Exception ex) { TraceUtil.WriteLineWarning (this, "error on cleanup: " + ex); // We tried... } ActiveX.CoFreeUnusedLibraries(); } return(type); } _typeFailedException = new Exception("Unable to determine CLR type because " + "I can't create a COM object (0x" + result.ToString("X") + ") from CLSID: " + _guidStr); throw _typeFailedException; }
// Finds the COM running objects public static IList GetRunningObjects(ProgressDialog progress) { ArrayList runningObjects = new ArrayList(); Hashtable runningHash = new Hashtable(); UCOMIBindCtx bc; UCOMIRunningObjectTable rot; UCOMIEnumMoniker em; UCOMIMoniker[] monikers = new UCOMIMoniker[1]; ActiveX.CreateBindCtx(0, out bc); bc.GetRunningObjectTable(out rot); rot.EnumRunning(out em); // Look at each Moniker in the ROT int unused; while (0 == em.Next(1, monikers, out unused)) { try { UCOMIMoniker moniker = monikers[0]; Object obj; rot.GetObject(moniker, out obj); String monikerName; moniker.GetDisplayName(bc, null, out monikerName); ComObjectInfo comObjInfo; // Check for duplicates against the other running objects Object runObj = runningHash[obj]; if (runObj != null) { // Get the existing object's moniker comObjInfo = (ComObjectInfo) ObjectInfo.GetObjectInfo(obj); if (monikerName.Equals(comObjInfo._monikerName)) { TraceUtil.WriteLineInfo (typeof(ComObjectInfo), "ROT - Skipping duplicate: " + monikerName); progress.UpdateProgress(1); continue; } } else { runningHash.Add(obj, obj); } comObjInfo = (ComObjectInfo) ObjectInfoFactory.GetObjectInfo(true, obj); // Need moniker name before update progress comObjInfo.CalcRunningObjName(rot, bc, moniker, monikerName); progress.UpdateProgressText(comObjInfo.GetMonikerName()); progress.UpdateProgress(1); runningObjects.Add(comObjInfo); TraceUtil.WriteLineIf(typeof(ComObjectInfo), TraceLevel.Info, "ROT - added: " + comObjInfo.GetName() + " " + comObjInfo.ObjType + " " + Win32Utils.RegKeyToString (comObjInfo._classIdKey) + Win32Utils.RegKeyToString (comObjInfo._classNameKey)); } catch (Exception ex) { TraceUtil.WriteLineIf(typeof(ComObjectInfo), TraceLevel.Info, "ROT - Exception processing ROT entry: " + ex); progress.UpdateProgress(1); continue; } } Marshal.ReleaseComObject(em); Marshal.ReleaseComObject(bc); Marshal.ReleaseComObject(rot); return(runningObjects); }