John
John

Reputation: 21

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?

Upvotes: 0

Views: 156

Answers (2)

John
John

Reputation: 21

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.

Upvotes: 1

Carlos E. Ferro
Carlos E. Ferro

Reputation: 948

GetTypeInfo is a function in the IDispatch interface, so your COM object must support IDispatch. First, you should call GetTypeInfoCount in order to see if the component provides type information. If it returns 0, then it doesn't.

If it does, just call comObject.GetTypeInfo(0, 0, pointer). The first argument identifies about what are you asking, 0 means "about the component". The sescond argument is the localeID, you could get it from the Kernel32.dll, but using 0 is the default for US english. The thid is an out argument, there the function puts a pointer to the ITypeInfo you are looking for.

After you have the ITypeInfo, to get the name you need still to get its documentation (GetDocumentation) and finally, the documentation has the name (and the help file, and the help context).

All of this is documented in MSDN, search the functions I have mentioned here for details

Upvotes: 0

Related Questions