?
Solved

Optional parameters for COM objects

Posted on 2004-09-23
5
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Accepted Solution

by:
eternal_21 earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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