Is it possible to define default values ​​for optional parameters in the COM interaction type?

I am using C # 4.0 to instantiate Excel.Application and open Excel.Workbook . My code is as follows:

 Excel.Application xlApp; Excel.Workbook xlWorkBook; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open("someFile"); 

The Open() method has a load of additional values ​​that I do not need to provide. This is convenient, except that I do not know what the default values ​​are for these optional parameters. Thus, I cannot decide if I need to provide a value.

In this case, I can find the information I need for some parameters in the MSDN documentation. Is there a general way to define default values ​​for optional parameters in the COM interaction type?

UPDATE:

Using oleview on MSO.dll , I checked the appropriate 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 think makes sense because the IDL does not provide any type information ( VARIANT ), nor about any default value. However, for the AccessMode parameter AccessMode IDL provides the necessary information, and intellisense displays it.

So now I ask the question: why is the IDL not more specific in terms of type (and default value) for all parameters, as for AccessMode ?

+4
source share
1 answer

why is the IDL not more specific with regard to type (and default values)

Specifically about the type, this is VARIANT. It is not necessary to specify a default value, the option may indicate "not specified." In fact, specifying the default value in the type library is possible, you saw this from the reconstructed IDL.

There is a lot of flexibility. But if the variant value is "not specified", the COM server will replace any value that it considers to be the default, or indicate a specific behavior for it that is not specified. The only way to find out what this might be is through documentation. Which is really not always stellar.

+3
source

All Articles