/// <summary>
        /// Consumes the COM component.
        /// </summary>
        static void ConsumeCOMComponent()
        {
            ATLDllCOMServerLib.SimpleObject simpleObj =
                new ATLDllCOMServerLib.SimpleObject();

            try
            {
                // Call the method: HelloWorld, that returns a string.
                {
                    string strResult = simpleObj.HelloWorld();
                    Console.WriteLine("Call HelloWorld => {0}", strResult);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The server throws the error: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Description: {0}", ex.InnerException.Message);
                }
            }

            Marshal.FinalReleaseComObject(simpleObj);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Consumes the COM component.
        /// </summary>
        static void ConsumeCOMComponent()
        {
            ATLDllCOMServerLib.SimpleObject simpleObj =
                new ATLDllCOMServerLib.SimpleObject();

            try
            {
                // Call the method: HelloWorld, that returns a string.
                {
                    string strResult = simpleObj.HelloWorld();
                    Console.WriteLine("Call HelloWorld => {0}", strResult);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The server throws the error: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Description: {0}", ex.InnerException.Message);
                }
            }

            Marshal.FinalReleaseComObject(simpleObj);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        static void EarlyBindtoComponent()
        {
            /////////////////////////////////////////////////////////////////////
            // Create an ATLDllCOMServer.SimpleObject COM object.
            //

            ATLDllCOMServerLib.SimpleObject simpleObj =
                new ATLDllCOMServerLib.SimpleObject();

            /////////////////////////////////////////////////////////////////////
            // Register the events of the COM object.
            //

            simpleObj.FloatPropertyChanging += new ATLDllCOMServerLib.
                _ISimpleObjectEvents_FloatPropertyChangingEventHandler(
                simpleObj_FloatPropertyChanging);

            /////////////////////////////////////////////////////////////////////
            // Consume the properties and the methods of the COM object.
            //

            try
            {
                // Set the property: FloatProperty, which raises the event
                // FloatPropertyChanging.
                {
                    Console.WriteLine("Set FloatProperty = {0,0:f2}", 1.2f);
                    simpleObj.FloatProperty = 1.2f;
                }

                // Get the property: FloatProperty.
                {
                    Console.WriteLine("Get FloatProperty = {0,0:f2}",
                        simpleObj.FloatProperty);
                }

                // Call the method: HelloWorld, that returns a string.
                {
                    string strResult = simpleObj.HelloWorld();
                    Console.WriteLine("Call HelloWorld => {0}", strResult);
                }

                // Call the method: GetProcessThreadID, that outputs two integers.
                {
                    Console.WriteLine("The client process and thread: {0}, {1}",
                        NativeMethod.GetCurrentProcessId(),
                        NativeMethod.GetCurrentThreadId());

                    int processId, threadId;
                    simpleObj.GetProcessThreadID(out processId, out threadId);
                    Console.WriteLine("Call GetProcessThreadID => {0}, {1}",
                        processId, threadId);
                }

                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("The server throws the error: {0}", ex.Message);
                if (ex.InnerException != null)
                    Console.WriteLine("Description: {0}", ex.InnerException.Message);
            }

            /////////////////////////////////////////////////////////////////////
            // Release the COM object.
            // It is strongly recommended against using ReleaseComObject to
            // manually release an RCW object that represents a COM component
            // unless you absolutely have to. We should generally let CLR release
            // the COM object in the garbage collector.
            // Ref: http://blogs.msdn.com/yvesdolc/archive/2004/04/17/115379.aspx
            //

            Marshal.FinalReleaseComObject(simpleObj);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        static void EarlyBindtoComponent()
        {
            /////////////////////////////////////////////////////////////////////
            // Create an ATLDllCOMServer.SimpleObject COM object.
            //

            ATLDllCOMServerLib.SimpleObject simpleObj =
                new ATLDllCOMServerLib.SimpleObject();


            /////////////////////////////////////////////////////////////////////
            // Register the events of the COM object.
            //

            simpleObj.FloatPropertyChanging += new ATLDllCOMServerLib.
                                               _ISimpleObjectEvents_FloatPropertyChangingEventHandler(
                simpleObj_FloatPropertyChanging);


            /////////////////////////////////////////////////////////////////////
            // Consume the properties and the methods of the COM object.
            //

            try
            {
                // Set the property: FloatProperty, which raises the event
                // FloatPropertyChanging.
                {
                    Console.WriteLine("Set FloatProperty = {0,0:f2}", 1.2f);
                    simpleObj.FloatProperty = 1.2f;
                }

                // Get the property: FloatProperty.
                {
                    Console.WriteLine("Get FloatProperty = {0,0:f2}",
                                      simpleObj.FloatProperty);
                }

                // Call the method: HelloWorld, that returns a string.
                {
                    string strResult = simpleObj.HelloWorld();
                    Console.WriteLine("Call HelloWorld => {0}", strResult);
                }

                // Call the method: GetProcessThreadID, that outputs two integers.
                {
                    Console.WriteLine("The client process and thread: {0}, {1}",
                                      NativeMethod.GetCurrentProcessId(),
                                      NativeMethod.GetCurrentThreadId());

                    int processId, threadId;
                    simpleObj.GetProcessThreadID(out processId, out threadId);
                    Console.WriteLine("Call GetProcessThreadID => {0}, {1}",
                                      processId, threadId);
                }

                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("The server throws the error: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Description: {0}", ex.InnerException.Message);
                }
            }


            /////////////////////////////////////////////////////////////////////
            // Release the COM object.
            // It is strongly recommended against using ReleaseComObject to
            // manually release an RCW object that represents a COM component
            // unless you absolutely have to. We should generally let CLR release
            // the COM object in the garbage collector.
            // Ref: http://blogs.msdn.com/yvesdolc/archive/2004/04/17/115379.aspx
            //

            Marshal.FinalReleaseComObject(simpleObj);
        }