static void Main(string[] args)
    {
        try
        {
            Guid           SWMgrClassObjectGuid = typeof(SWLMLib.SWMgrClass).GUID;                  //{8EAAFAD7-73F8-403B-A53B-4400E16D8EDF}
            Guid           IUnknownGuid         = new Guid("00000000-0000-0000-C000-000000000046"); //Can it be written in more pretty style?
            SWLMLib.ISWMgr lintfSWLMgr          = null;

            /* This will create IN-PROC Server because, it seems CoCreateInstance will be invoked with CLSCTX_INPROC_SERVER flag settled
             * Type type = Type.GetTypeFromCLSID(SWMgrClassObjectGuid), true);
             * object instance0 = Activator.CreateInstance(type);
             * lintfSWLMgr = (instance0 as SWLMLib.ISWMgr); */
            Guid   Ev1      = typeof(ISWMgrEvents).GUID;
            object instance = null;
            unsafe
            {
                UInt32 dwRes = CoCreateInstance(SWMgrClassObjectGuid,
                                                IntPtr.Zero,
                                                (uint)(CLSCTX.CLSCTX_LOCAL_SERVER),     //if OR with CLSCTX_INPROC_SERVER then INPROC Server will be created, because of DLL COM Server
                                                IUnknownGuid,
                                                out instance);
                if (dwRes != 0)
                {
                    int iError = Marshal.GetLastWin32Error();
                    Console.WriteLine("CoCreateInstance Error = {0}, LastWin32Error = {1}", dwRes, iError);
                    return;
                }
                lintfSWLMgr = (instance as SWLMLib.ISWMgr);
            }
            if (lintfSWLMgr != null)
            {
                //lintfSWLMgr.InitializeMethod(...); //Initialize object
                //Find Connection Point for Events
                Guid                      ISWMgrEventsGuid = typeof(SWLMLib.ISWMgrEvents).GUID; //{C13A9D38-4BB0-465B-BF4A-487F371A5538} Interface for Evenets Handling
                IConnectionPoint          lCP  = null;
                IConnectionPointContainer lCPC = (instance as IConnectionPointContainer);
                lCPC.FindConnectionPoint(ref ISWMgrEventsGuid, out lCP);
                MySink lSink = new MySink();
                Int32  dwEventsCookie;
                lCP.Advise(lSink, out dwEventsCookie);
                Console.WriteLine("Waiting for Events Handling...");
                Console.WriteLine("Press ENTER to Exit...");
                Console.ReadLine();     // Until Eneter is not hit, the events arrive properly
                //Here starting to Unsubscribe for Events and Com Objects CleanUP
                lCP.Unadvise(dwEventsCookie);
                Marshal.ReleaseComObject(lCP);
                Marshal.ReleaseComObject(lintfSWLMgr);
            }
        }
        catch (Exception E)
        {
            Console.WriteLine(E.Message);
            throw;
        }
    }
Ejemplo n.º 2
0
        public static void Run()
        {
            MySrc.Register();
            MySink.Register();

            MySrc  mysrc  = Gst.ElementFactory.Make("mysrc") as MySrc;
            MySink mysink = Gst.ElementFactory.Make("mysink") as MySink;

            Gst.Pipeline pipeline = new Pipeline("pipeline");
            pipeline.Add(mysrc, mysink);
            Assert.IsTrue(mysrc.Link(mysink));

            loop = new MainLoop();

            pipeline.Bus.AddWatch(new BusFunc(BusCb));
            pipeline.SetState(Gst.State.Playing);

            loop.Run();

            pipeline.SetState(Gst.State.Null);
        }