Solved

Optional parameters for COM objects

Posted on 2004-09-23
5
217 Views
Last Modified: 2010-04-15
I have a COM object that I am attempting to make a function call from C#.  It has some parameters that I have no idea what to pass it.  When I make this same function call in VB.Net it does not require these parameters and compiles and runs fine without them.  Therefore I am assuming that these parameters are optional.  The parameters' type are all "object".  Is there a way to get C# to make the call the way VB.Net does?

Thanks

0
Comment
Question by:d532335
5 Comments
 
LVL 10

Accepted Solution

by:
eternal_21 earned 50 total points
ID: 12135289
You could try passing System.Reflection.Missing.Value?
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12135317
You could try to simply pass null?
0
 

Author Comment

by:d532335
ID: 12135531
I have tryed passing null, and the empty string "".  Both caused an exception.
0
 
LVL 8

Expert Comment

by:rajaloysious
ID: 12135548
You can create ONE new object, set it to null and send this same object for all missing optional parameters...
***********
A bit of which i have read....
The actual way optional parameters work in VB.NET is that
it internally creates objects or variables and call the procedure.
A.Method1(,,,,,1,2)
actually means it creates the first 5 parameters and send them .

So if there are more no of missing parameters, it creates one object or variable for each and sends them.
So it is slower.
*******
In C# though you can create one object, set it to null and use the same object for all your missing parameters.
In this way, the memory usage is minimal and perfomance gained...
0
 

Author Comment

by:d532335
ID: 12135579
eternal21's suggestion worked.  I appreciate the help.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question