Solved

Optional parameters for COM objects

Posted on 2004-09-23
5
218 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

696 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