Solved

Optional parameters for COM objects

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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