Example #1
0
 public void RegisterForRelease(IModuleData module)
 {
     if (module != null)
     {
         COMHelper.Release(module.LegacyMetaDataImport);
     }
 }
Example #2
0
        internal override IModuleData GetModuleData(ulong addr)
        {
            if (addr == 0)
            {
                return(null);
            }

            IModuleData result;

            if (CLRVersion == DesktopVersion.v2)
            {
                V2ModuleData data = new V2ModuleData();
                if (!RequestStruct(DacRequests.MODULE_DATA, addr, ref data))
                {
                    return(null);
                }

                COMHelper.Release(data.MetaDataImport);
                result = data;
            }
            else
            {
                V4ModuleData data = new V4ModuleData();
                if (!RequestStruct(DacRequests.MODULE_DATA, addr, ref data))
                {
                    return(null);
                }

                COMHelper.Release(data.MetaDataImport);
                result = data;
            }

            return(result);
        }
Example #3
0
 void IDisposable.Dispose()
 {
     Trace.TraceInformation($"SOSHost.Dispose {_disposed}");
     if (!_disposed)
     {
         _disposed = true;
         TargetWrapper.Release();
         COMHelper.Release(_interface);
     }
 }
Example #4
0
        public override void Stop()
        {
            COMHelper.ShutdownCOMApplication(this.args.CategoryName);

            if (COMHelper.HasCOMComponent(this.args.AppName))
            {
                COMHelper.DeleteCOMComponent(this.args.AppName);
            }

            COMHelper.ShutdownCOMApplication(this.args.CategoryName);
        }
Example #5
0
 public static void Unregister(Type t)
 {
     try
     {
         COMHelper.RegasmUnregisterLocalServer(t);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message); // 记录错误
         throw ex;                      // 再次抛出异常
     }
 }
 public static void Unregister(Type t)
 {
     try
     {
         COMHelper.RegasmUnregisterLocalServer(t);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message); // Log the error
         throw ex;                      // Re-throw the exception
     }
 }
 public static void Register(Type t)
 {
     try
     {
         COMHelper.RegasmRegisterLocalService(t, new Guid(AppId), ServiceName);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message); // Log the error
         throw ex;                      // Re-throw the exception
     }
 }
Example #8
0
        public async Task OpenVirtualProcess(TestConfiguration config)
        {
            // The current Linux test assets are not alpine/musl
            if (OS.IsAlpine)
            {
                throw new SkipTestException("Not supported on Alpine Linux (musl)");
            }
            if (!config.AllSettings.ContainsKey("DumpFile"))
            {
                throw new SkipTestException("OpenVirtualProcessTest: No dump file");
            }
            await RemoteInvoke(config, nameof(OpenVirtualProcess), static (string configXml) =>
            {
                AfterInvoke(configXml, out TestConfiguration cfg, out ITestOutputHelper output);

                DbgShimAPI.Initialize(cfg.DbgShimPath());
                AssertResult(DbgShimAPI.CLRCreateInstance(out ICLRDebugging clrDebugging));
                Assert.NotNull(clrDebugging);

                TestDump testDump = new(cfg);
                ITarget target    = testDump.Target;
                IRuntimeService runtimeService = target.Services.GetService <IRuntimeService>();
                IRuntime runtime = runtimeService.EnumerateRuntimes().Single();

                CorDebugDataTargetWrapper dataTarget            = new(target.Services);
                LibraryProviderWrapper libraryProvider          = new(target.OperatingSystem, runtime.RuntimeModule.BuildId, runtime.GetDbiFilePath(), runtime.GetDacFilePath());
                ClrDebuggingVersion maxDebuggerSupportedVersion = new()
                {
                    StructVersion = 0,
                    Major         = 4,
                    Minor         = 0,
                    Build         = 0,
                    Revision      = 0,
                };
                HResult hr = clrDebugging.OpenVirtualProcess(
                    runtime.RuntimeModule.ImageBase,
                    dataTarget.ICorDebugDataTarget,
                    libraryProvider.ILibraryProvider,
                    maxDebuggerSupportedVersion,
                    in RuntimeWrapper.IID_ICorDebugProcess,
                    out IntPtr corDebugProcess,
                    out ClrDebuggingVersion version,
                    out ClrDebuggingProcessFlags flags);

                AssertResult(hr);
                Assert.NotEqual(IntPtr.Zero, corDebugProcess);
                Assert.Equal(1, COMHelper.Release(corDebugProcess));
                Assert.Equal(0, COMHelper.Release(corDebugProcess));
                Assert.Equal(0, clrDebugging.Release());
                return(Task.FromResult(0));
            });
Example #9
0
        public override void ValidateArguments()
        {
            base.ValidateArguments();

            if (string.IsNullOrEmpty(this.args.CategoryName))
            {
                throw new ArgumentNullException("categoryName", "categoryName can not be null or empty");
            }

            if (!this.args.NoStop && !COMHelper.HasCOMComponent(this.args.AppName))
            {
                throw new ArgumentException(this.args.AppName + " component could not be found", "appName");
            }
        }
        /// <summary>
        /// 关闭应用
        /// </summary>
        private void Close()
        {
            if (_wb != null)
            {
                COMHelper.ReleaseObject(_wb);
            }

            if (_isNewApp && _appCreatedTimeBegin != null && _appCreatedTimeEnd != null)
            {
                COMHelper.KillProcessByNameAndStartTime(Aim.Component.ThirdpartySupport.Application.MS_OFFICE_EXCEL_PROCESS_NAME,
                                                        _appCreatedTimeBegin.Value, _appCreatedTimeEnd.Value);
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #11
0
        // 动态库环境注册检查
        private static bool CheckRegSvrDll(out string errMsg)
        {
            string sourcePath = XMLHelper.CurSystemPath + @"Lib\OPCDAAuto.dll";

            //    string targetPath = Path.Combine(@"C:\Windows\SysWOW64", @"OPCDAAuto.dll");
            errMsg = "";
            string opcDAAUtoClsID = "28E68F9A-8D75-11D1-8DC3-3C302A000000";// 可F12到这个动态库查看它的GUID码

            try
            {
                if (!Environment.Is64BitOperatingSystem)
                {
                    return(true); // 32位系统无需注册
                }
                if (COMHelper.IsRegister(opcDAAUtoClsID, out string filePath))
                {
                    // 系统已经注册该COM组件,判断路径是不是该程序自带这个dll
                    if (sourcePath.ToUpper() == filePath.ToUpper())
                    {
                        return(true);
                    }
                    else
                    {
                        // 不是同一个路径,卸载掉,重新自带的dll,防止版本不一致
                        if (!COMHelper.IsRegsvr32(opcDAAUtoClsID, filePath, false, out errMsg))
                        {
                            errMsg = "未能成功卸载" + filePath + "这个版本dll,无法解决版本一致性问题";
                        }
                    }
                }
                if (!File.Exists(sourcePath))
                {
                    errMsg = "未发现该文件,注册失败" + sourcePath;
                }

                bool a = COMHelper.IsRegsvr32(opcDAAUtoClsID, sourcePath, true, out errMsg);
                return(a);
            }
            catch (Exception e)
            {
                errMsg = e.Message + e.StackTrace;
                return(false);
            }
        }
        protected override void DoStopInternal(object state)
        {
            IFilterGraph graph = mediaControl as IFilterGraph;

            if (graph != null)
            {
                if (mediaControl != null)
                {
                    int hr = mediaControl.Stop();
                    DsError.ThrowExceptionForHR(hr);
                    mediaControl = null;
                }

                IEnumFilters pEnum = null;
                if (COMHelper.SUCCEEDED(graph.EnumFilters(out pEnum)) && pEnum != null)
                {
                    List <IBaseFilter> allFilters = new List <IBaseFilter>();

                    IBaseFilter[] aFilters = new IBaseFilter[1];
                    while (COMHelper.S_OK == pEnum.Next(1, aFilters, IntPtr.Zero))
                    {
                        allFilters.Add(aFilters[0]);
                    }
                    Marshal.ReleaseComObject(pEnum);

                    foreach (var f in allFilters)
                    {
                        if (f != null)
                        {
                            graph.RemoveFilter(f);
                        }
                    }
                }
            }

            base.DoStopInternal(state);
        }
Example #13
0
        public override void Start()
        {
            string dllPath = Path.Combine(this.args.AppFolder, this.args.AppName + EXT);

            COMHelper.InstallCOMComponent(this.args.CategoryName, dllPath);
        }
        //初始化端口函数
        public Boolean initCOM()
        {
            String portName = "COM1";

            if (ini.IniReadValue("设置", "portSelected") != "")
            {
                portName = ini.IniReadValue("设置", "portSelected");
            }
            int baudRate = 9600;

            if (ini.IniReadValue("设置", "baudRate") != "")
            {
                baudRate = Int32.Parse(ini.IniReadValue("设置", "baudRate"));
            }

            int dataBits = 8;

            if (ini.IniReadValue("设置", "dataBits") != "")
            {
                dataBits = Int32.Parse(ini.IniReadValue("设置", "dataBits"));
            }

            StopBits oStopBits = StopBits.One;

            switch (ini.IniReadValue("设置", "stopBits"))
            {
            case "1":
                oStopBits = StopBits.One;
                break;

            case "1.5":
                oStopBits = StopBits.OnePointFive;
                break;

            case "2":
                oStopBits = StopBits.Two;
                break;

            default:
                oStopBits = StopBits.One;
                break;
            }

            //无奇偶校验位
            Parity oParity = Parity.None;

            switch (ini.IniReadValue("设置", "parity"))
            {
            case "无":
                oParity = Parity.None;
                break;

            case "奇校验":
                oParity = Parity.Odd;
                break;

            case "偶校验":
                oParity = Parity.Even;
                break;

            default:
                oParity = Parity.None;
                break;
            }

            int ReadTimeout  = 100;
            int WriteTimeout = -1;

            comHelp = new COMHelper(portName, baudRate, oParity, dataBits, oStopBits, ReadTimeout, WriteTimeout);
            if (!comHelp.IsOpen())
            {
                if (!comHelp.Open())
                {
                    MessageBox.Show("端口打开失败", "提示");
                    //退出
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("端口被占用", "提示");
                //退出
                return(false);
            }

            comHelp.AddReceiveEventHanlder(comHelp.serialPort_DataReceived);//将接收到数据,处理数据的方法注册进去
            comHelp.ReceiveDataHandler += rds_ReceiveDataHandler;
            return(true);
        }