How can I find out the properties and methods of COM objects returned from some .NET functions, which do not appear to be documented?
In the particular example I’m looking at, I’m inserting a picture into Excel using a function like:
Set NewPic = ActiveSheet.Pictures.Insert(FileName)
(See the SO post on this here.)
However, the MSDN documentation for this function only says that Worksheet.Pictures returns an Object, and when I put a watch on the variable during debugging its type is System.__ComObject. Can I find out what other properties and functions might be available for that class (for example, I want to modify the alternative text for the picture)? How would the person who found out about the Insert function even have known about it?
The MSDN doc also tends to say of such functions that they are ‘not intended to be used directly from your code’, but let’s ignore that for now…
Thanks!
Edit: Well, I managed to answer my specific question at least. Instead of using Worksheet.Pictures.Insert, you can use Worksheet.Shapes.AddPicture to return a proper (documented) Excel.Shape class:
pic = range.Worksheet.Shapes.AddPicture(tmpFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, range.Left, range.Top, image.Width, image.Height) pic.AlternativeText = 'Help!'
Would still be interested in any resources for undocumented functions though.
One way to find these things out is to use the
OleViewtool (which you can download from Microsoft here). This tool allows you to view COM Type Libraries. The Type Library (assuming the vendor of the COM component provided type library information) contains information about the interfaces and the methods and properties of the COM classes exposed by an application or library.For example, on my machine, I can view the Type Library for
C:\Program Files\Microsoft Office\Office12\EXCEL.EXEand see what COM objects are exposed by Excel, and their properties and methods.OleViewdisplays information in IDL (Interface Description Language), which is more or less a C function prototype with extra attributes tacked on).This is the IDL declaration I got using
OleViewfor the__Worksheet.Picturesproperty:Note the
hiddenattribute on the declaration. This means it won’t be displayed by most IDE’s (and is a good hint to not rely on this method always existing – Microsoft could remove it in a later version of Excel).Now what about the
Picturesclass? Here is the full IDL:From this, you can surmise that the
Picturesinterface has aCutandDeletemethod, as well as anItemproperty, among others. However, note that this interface is also markedhidden, which (again) is a good indication that you shouldn’t really be using it (yes, I know you were ignoring that warning, but I second Mitch Wheat’s comment that it’s generally a bad idea to use hidden classes, because they are usually meant for the application’s own internal use and are subject to change without notice.)