Solved

Optional parameters for COM objects

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now