Search code examples
.netcom

How to get name of the com object control in .Net?


I am accessing a COM object in a .net application. I want to get the Name of this COM object supplied at the design time.

I have googled and understood that the way to get the name is through GetTypeInfo api. But I am not sure how to use it.

Can any one suggest a solution for it?


Solution

  • Finally, I could make this work. Following are the steps I have followed to get the name assigned to control at design time from COM object:

     ‘Name’ property is not directly available on IDispatch interface

    • Using IDispatch interface on the COM object, we can invoke standard properties and methods. Using this, we were able to retrieve properties like HWND, Font etc. but we were not able to retrieve Name property.

     Understanding Extender properties

    • Some properties of a control are provided by the container rather than the control; these are extender properties. Examples of extender properties are: Name, Tag and Left. The control still needs to know what the value of these extender properties are, and sometimes needs to be able to change an extender property; the Extender object gives the control access to these properties.

     Now, the next challenge is to get extender object from the available COM object.

    • COM object has some standard OLE interface implemented on it. So using those interfaces we can retrieve the extender object. A detailed information of the interfaces available on COM object is listed in the following link.
    • Retrieving extended object is not a direct step. To achieve this,

      First, we need to get pointer to IOleObject interface on the control. This can be retrieved using QueryInterface API.

      Using IOleObject pointer, we have to get hold of ClientSite associated with the control. This can be achieved using GetClientSite API available on IOleObject interface. This returns a pointer to IOleClientSite interface.

      From IOleClientSite interface pointer, we have to retrieve ControlSite. This is achieved by querying for IOleControlSite interface on it. This returns a pointer to IOleControlSite interface.

      Extender object can be retrieved using IOleControlSite interface using GetExtendedControl API available on it.

      To access Name property on extender control object, we have to get pointer to IDispatch interface and query for it.