none
I want Create an OLE Automation Server In C# VS2010

    Question

  • Hi Every One ,

       Iam Completely new to OLE , I want Create an OLE Automation Server app in C# VS2010.it should expose one function through OLE techonolgy so that this function can called from Other Technology such as SAP. Kindly tell me how i can start ,

       Any small Sample would be great for me to begin


    suresh

    Thursday, October 11, 2012 4:31 AM

Answers

  • Hello sureshcse29,

    Hope the following article will be helpful to you :

    Creating a COM Server Using C#.

    http://limbioliong.wordpress.com/2011/08/30/creating-a-com-server-using-c/

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    Thursday, October 11, 2012 4:56 AM
  • Hello sureshcse29,

    1. The term "OLE" is an acronym for "Object Linking and Embedding". It used to be closely connected with embedding objects of one document type within another (e.g. an Excel Spreadsheet within a Word Document).

    2. It was also connected with being able to invoke actions on embedded objects and getting embedded objects to alert container objects when certain events of interest occurs.

    3. OLE is based entirely on COM (Component Object Model) which is a lower-level technology :

    3.1 The technology of embedding objects within a container is based on the IOleInPlaceSite, IOleInPlaceObject, IOleInPlaceActiveObject, etc. interfaces. All these are COM interfaces but associated with OLE.

    3.2 The technology of invoking actions on an embedded object is based on the IDispatch interface which is also a COM interface. IDispatch used to be associated with the term "OLE Automation" but is now so commonly used that it is known simply as "Automation".

    3.3 The technology to alert container objects is also known as events which is based on the IConnectionPoint and IConnectionPointContainer interfaces. These are all COM interfaces. Events were once also closely connected with OLE but is now more closely associated with COM.

    3.4 The supreme example of OLE technology is the ActiveX control which was also once known as OLE controls (hence OCX).

    4. Hence to answer your question : I would say COM is a superset of OLE. All that can be found in OLE is in COM (but not the other way around).

    5. Hope the above is helpful to you.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Thursday, October 11, 2012 5:54 AM
  • Hello suresh,

    1. A COM category is a set of COM interfaces that are logically grouped into a set and is known by a GUID also known as a CATID. COM Components which classify themselves as being of a certain category are expected to implement those interfaces. This is to help clients to be able to quickly identify objects which will definitely implement an expected set of interfaces and use them as appropriate.

    2. Your "abc" class, for instance, being contained in a .NET assembly, is automatically classified as a .NET category COM object. Hence it is contained in that category in OLEVIEW.

    3. OLEVIEW got this bit of information from the registry where your "abc" class is recorded. Perform the following :

    3.1 Look up the registry under the key : HKEY_CLASSES_ROOT\CLSID\{3C5E5DED-D27C-435A-9D88-4DF04AEF5436}.

    3.2 Here, you will see the following sub-key :

    HKEY_CLASSES_ROOT\CLSID\{3C5E5DED-D27C-435A-9D88-4DF04AEF5436}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}

    The {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} GUID indicates the ".NET Category". The registration of this category is automatically generated for your assembly by REGASM.EXE.

    4. The "Automation Objects" category is obviously for COM components that at minimum implement the IDispatch interface. This will be so for most .NET-based COM-Visible object unless deliberately configured otherwise.

    5. Your "abc" class, even though decorated with the "[ClassInterface(ClassInterfaceType.None)]" attribute, nevertheless exposes the IDispatch interface via the _Object interface (which is a COM-visible .NET interface, from the .NET "Object" class).

    6. To register your "abc" class as being of the "Automation Objects" category, you need to record this information in the registry when REGASM.EXE is run on your assembly.

    7. To do so, you need to supply 2 functions decorated with the ComRegisterFunctionAttribute and the ComUnregisterFunctionAttribute in your abc class. These are custom functions which will be called during REGASM and in which custom actions may be invoked. You can take advantage of this and register your abc class as being of "Automation Objects" category (GUID : {40FC6ED5-2438-11CF-A3DB-080036F12502})

    For more information, please read :

    Perform Custom Action during Registration of a Managed COM Server.

    http://limbioliong.wordpress.com/2011/08/30/adding-additional-data-when-registering-c-com-servers/

    8. Here is a sample implementation for your reference :

    [ComVisible(true)]
    [Guid("3C5E5DED-D27C-435A-9D88-4DF04AEF5436")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMInteroperate")]
    public class abc
    {
        public void Method() { }
    
        // Each class which is to have custom registration performed
        // must contain its own ComRegisterFunctionAttribute marked
        // function.
        [ComRegisterFunction]
        public static void RegisterFunction(Type t)
        {
            // Perform custom action during registration
            // of assembly.
    
            // Add a custom key to the registry
            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(
              "CLSID\\" + t.GUID.ToString("B") + "\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}");
    
            if (key != null)
            {
                // Add default value to the custom key.
                key.Close();
            }
        }
    
        // Each class which is to have custom unregistration performed
        // must contain its own ComUnregisterFunctionAttribute marked
        // function.
        [ComUnregisterFunction]
        public static void UnregisterFunction(Type t)
        {
            // Perform custom action during unregistration
            // of assembly.
            //
            // This method should basically undo the work
            // done in the registration function.
            Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(
              "CLSID\\" + t.GUID.ToString("B") + "\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}", false);
        }
    }

    9. "OLE 1.0 Objects" is not a COM category. It is a classification of old OLE objects that pre-date the advent of COM technology. For more information, lookup :

    "Object Linking and Embedding"

    http://en.wikipedia.org/wiki/Object_Linking_and_Embedding

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    Friday, October 12, 2012 11:15 AM

All replies

  • Hello sureshcse29,

    Hope the following article will be helpful to you :

    Creating a COM Server Using C#.

    http://limbioliong.wordpress.com/2011/08/30/creating-a-com-server-using-c/

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    Thursday, October 11, 2012 4:56 AM
  • Hi Lim Bio Liong,

    I have a doubt is OLE and COM are same ,if same why two names OLE,COM,iam entirely new to OLE and COM.


    suresh

    Thursday, October 11, 2012 5:10 AM
  • Hello sureshcse29,

    1. The term "OLE" is an acronym for "Object Linking and Embedding". It used to be closely connected with embedding objects of one document type within another (e.g. an Excel Spreadsheet within a Word Document).

    2. It was also connected with being able to invoke actions on embedded objects and getting embedded objects to alert container objects when certain events of interest occurs.

    3. OLE is based entirely on COM (Component Object Model) which is a lower-level technology :

    3.1 The technology of embedding objects within a container is based on the IOleInPlaceSite, IOleInPlaceObject, IOleInPlaceActiveObject, etc. interfaces. All these are COM interfaces but associated with OLE.

    3.2 The technology of invoking actions on an embedded object is based on the IDispatch interface which is also a COM interface. IDispatch used to be associated with the term "OLE Automation" but is now so commonly used that it is known simply as "Automation".

    3.3 The technology to alert container objects is also known as events which is based on the IConnectionPoint and IConnectionPointContainer interfaces. These are all COM interfaces. Events were once also closely connected with OLE but is now more closely associated with COM.

    3.4 The supreme example of OLE technology is the ActiveX control which was also once known as OLE controls (hence OCX).

    4. Hence to answer your question : I would say COM is a superset of OLE. All that can be found in OLE is in COM (but not the other way around).

    5. Hope the above is helpful to you.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    Thursday, October 11, 2012 5:54 AM
  • Hi Lim Bio Liong,

    Thanks for Reply,it helped me a lot.

    after Refering to above mention article 

    [ComVisible(true)]
    [Guid("3C5E5DED-D27C-435A-9D88-4DF04AEF5436")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMInteroperate")]

    Public Class abc

    {

       public void Method() {}

    After install this class i could find this .Net Catergory for of ObJect Class .U can find this Attached Image.but i could find two other tabs  Automation Objects(SubSet of .Net Category) and OLE 1.0 Objects.Can U help me what are those what should i do show my Progid in those things too.refer Image attached.COM_objects_Image


    suresh

    Friday, October 12, 2012 7:58 AM
  • Hello suresh,

    1. A COM category is a set of COM interfaces that are logically grouped into a set and is known by a GUID also known as a CATID. COM Components which classify themselves as being of a certain category are expected to implement those interfaces. This is to help clients to be able to quickly identify objects which will definitely implement an expected set of interfaces and use them as appropriate.

    2. Your "abc" class, for instance, being contained in a .NET assembly, is automatically classified as a .NET category COM object. Hence it is contained in that category in OLEVIEW.

    3. OLEVIEW got this bit of information from the registry where your "abc" class is recorded. Perform the following :

    3.1 Look up the registry under the key : HKEY_CLASSES_ROOT\CLSID\{3C5E5DED-D27C-435A-9D88-4DF04AEF5436}.

    3.2 Here, you will see the following sub-key :

    HKEY_CLASSES_ROOT\CLSID\{3C5E5DED-D27C-435A-9D88-4DF04AEF5436}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}

    The {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} GUID indicates the ".NET Category". The registration of this category is automatically generated for your assembly by REGASM.EXE.

    4. The "Automation Objects" category is obviously for COM components that at minimum implement the IDispatch interface. This will be so for most .NET-based COM-Visible object unless deliberately configured otherwise.

    5. Your "abc" class, even though decorated with the "[ClassInterface(ClassInterfaceType.None)]" attribute, nevertheless exposes the IDispatch interface via the _Object interface (which is a COM-visible .NET interface, from the .NET "Object" class).

    6. To register your "abc" class as being of the "Automation Objects" category, you need to record this information in the registry when REGASM.EXE is run on your assembly.

    7. To do so, you need to supply 2 functions decorated with the ComRegisterFunctionAttribute and the ComUnregisterFunctionAttribute in your abc class. These are custom functions which will be called during REGASM and in which custom actions may be invoked. You can take advantage of this and register your abc class as being of "Automation Objects" category (GUID : {40FC6ED5-2438-11CF-A3DB-080036F12502})

    For more information, please read :

    Perform Custom Action during Registration of a Managed COM Server.

    http://limbioliong.wordpress.com/2011/08/30/adding-additional-data-when-registering-c-com-servers/

    8. Here is a sample implementation for your reference :

    [ComVisible(true)]
    [Guid("3C5E5DED-D27C-435A-9D88-4DF04AEF5436")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMInteroperate")]
    public class abc
    {
        public void Method() { }
    
        // Each class which is to have custom registration performed
        // must contain its own ComRegisterFunctionAttribute marked
        // function.
        [ComRegisterFunction]
        public static void RegisterFunction(Type t)
        {
            // Perform custom action during registration
            // of assembly.
    
            // Add a custom key to the registry
            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(
              "CLSID\\" + t.GUID.ToString("B") + "\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}");
    
            if (key != null)
            {
                // Add default value to the custom key.
                key.Close();
            }
        }
    
        // Each class which is to have custom unregistration performed
        // must contain its own ComUnregisterFunctionAttribute marked
        // function.
        [ComUnregisterFunction]
        public static void UnregisterFunction(Type t)
        {
            // Perform custom action during unregistration
            // of assembly.
            //
            // This method should basically undo the work
            // done in the registration function.
            Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(
              "CLSID\\" + t.GUID.ToString("B") + "\\Implemented Categories\\{40FC6ED5-2438-11CF-A3DB-080036F12502}", false);
        }
    }

    9. "OLE 1.0 Objects" is not a COM category. It is a classification of old OLE objects that pre-date the advent of COM technology. For more information, lookup :

    "Object Linking and Embedding"

    http://en.wikipedia.org/wiki/Object_Linking_and_Embedding

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/


    Friday, October 12, 2012 11:15 AM