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
OleView
tool (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.EXE
and see what COM objects are exposed by Excel, and their properties and methods.OleView
displays 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
OleView
for the__Worksheet.Pictures
property:Note the
hidden
attribute 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
Pictures
class? Here is the full IDL:From this, you can surmise that the
Pictures
interface has aCut
andDelete
method, as well as anItem
property, 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.)