Reputation: 21
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
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
Understanding Extender properties
Now, the next challenge is to get extender object from the available COM object.
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
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