Is it possible to determine default values of optional parameters in a COM interop type?
c#, c#-4.0, com
Solution
why is the IDL not more specific about the type (and default value)
It is specific about the type, it is VARIANT. It doesn't have to be specific about the default value, a variant is capable of specifying "not specified". Actually specifying the default value in the type library is possible, you saw that from the reverse-engineered IDL.
Lots of flexibility here. But if the variant value is "not specified" then the COM server will substitute whatever value it considers the default or give specific behavior to it not being specified. The only way to find out what that might be is through the documentation. Which indeed isn't always stellar.
Problem
I am using C# 4.0 to instantiate an `Excel.Application` and open an `Excel.Workbook`. Stripped down, my code looks like this: ``` Excel.Application xlApp; Excel.Workbook xlWorkBook; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open("someFile"); ``` The `Open()` method has a load of optional values that I do not need to provide. That is convenient, except that I do not know what the default values for those optional parameters are. As such, I can not decide whether or not I have to provide a value. In this case, I can find the desired information for some parameters in the MSDN documentation. Is there a generic way to determine the default values for optional parameters in a COM interop type? UPDATE: Using `oleview` on `MSO.dll`, I checked out the corresponding IDL for the `Workbook` interface. For the `SaveAs()` method, it looks like this: ``` HRESULT SaveAs( [in, optional] VARIANT Filename, [in, optional] VARIANT FileFormat, [in, optional] VARIANT Password, blahblah... [in, optional, defaultvalue(1)] XlSaveAsAccessMode AccessMode, blahblah... [in, optional] VARIANT Local, [in, lcid] long lcid); ``` In Visual Studio, intellisense shows `[object Filename = Type.Missing]` for most parameters, which I guess makes sense because the IDL does not give any information about type (`VARIANT`) nor about any default value. For the parameter `AccessMode` however, the IDL provides the required information and intellisense shows it. So I guess the question now becomes: why is the IDL not more specific about the type (and default value) of all parameters, just like it is for `AccessMode`?