Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace);

            MyMethodClass method  = new MyMethodClass();
            IWelcome      welcome = method;

            method.Completed += method_Completed;
            Console.WriteLine(welcome.Greeting("Polaris"));
            Marshal.ReleaseComObject(method);

            try
            {
                Console.WriteLine(welcome.Greeting("Polaris"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            //Type t = Type.GetTypeFromProgID("PlsInteropCOMServerLib.MyMethodClass");
            //dynamic o = Activator.CreateInstance(t);
            //Console.WriteLine(t.ToString());

            Console.ReadKey();
        }
        public static void InvokeIWelcome()
        {
            // If the object — as in this case — offers multiple interfaces, a variable of the other interface can be
            // declared, and by using a simple assignment with the cast operator, the wrapper class does a
            // QueryInterface() with the COM object to return the second interface pointer.

            IWelcome welcome = comObj;

            Alert.Show(welcome.Greeting("Heya! I'm Greeting() invoked from the COM!!"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var      obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("John"));
            //
            IMath math = (IMath)obj;
            int   x    = math.Add(3, 5);

            Console.WriteLine(x);
            //释放内存
            Marshal.ReleaseComObject(math);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            COMDemo  obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Stephanie"));

            IMath math;

            math = (IMath)welcome;
            int x = math.Add(4, 5);

            Console.WriteLine(x);
        }
Beispiel #5
0
        private static void Main()
        {
            var      obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Stephanie"));

            obj.Completed += () => Console.WriteLine("Calculation completed");

            var math = (IMath)welcome;
            var x    = math.Add(4, 5);

            Console.WriteLine(x);

            Marshal.ReleaseComObject(math);
        }
Beispiel #6
0
        static void Main()
        {
            COMDemo  obj     = new COMDemo();
            IWelcome welcome = obj;

            Console.WriteLine(welcome.Greeting("Christian"));

            obj.Completed += () => Console.WriteLine("Calculation completed");
            //delegate
            //{
            //   Console.WriteLine("Calculation completed");
            //};

            IMath math;

            math = (IMath)welcome;
            int x = math.Add(4, 5);

            Console.WriteLine(x);

            Marshal.ReleaseComObject(math);
        }