473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C#, COM Interop & Default parameters

Hi All,

I am trying to use a COM component that has methods with default parameters.
How can I call these methods from C#. Not all default values are in the
documentation of the control.

Thanks

Colin
Nov 22 '05 #1
2 3096
Colin,

If the parameters have default values, then that means that they are
also optional parameters. In order to get the default value to be used, you
should pass the value returned from the static Value property on the Missing
class in the System.Reflection namespace.

The only problem that you will run into is when an interface is not
completely automation-compliant. VB and MIDL compilers allow interfaces to
have optional parameters that were of a type other than a variant. If your
COM components are like this, then you will have a problem, I think, because
the optional parameter will be exposed as that type, and trying to pass
Missing.Value will throw a InvalidCastException (I believe).

In this case, you might want to do some reflection (in the COM sense) on
the type library, getting the type, and then looking at the method
information. You should be able to get what you need through the ITypeLib
and ITypeInfo (their .NET counterparts being UCOMITypeLib and UCOMITypeInfo)
interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CMan" <cm**@nospam.nospam> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I am trying to use a COM component that has methods with default parameters. How can I call these methods from C#. Not all default values are in the
documentation of the control.

Thanks

Colin

Nov 22 '05 #2
Thanks Nicholas

I'll have look at this. I may resort to VB for these few forms.

Colin
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:On**************@tk2msftngp13.phx.gbl...
Colin,

If the parameters have default values, then that means that they are
also optional parameters. In order to get the default value to be used, you should pass the value returned from the static Value property on the Missing class in the System.Reflection namespace.

The only problem that you will run into is when an interface is not
completely automation-compliant. VB and MIDL compilers allow interfaces to have optional parameters that were of a type other than a variant. If your COM components are like this, then you will have a problem, I think, because the optional parameter will be exposed as that type, and trying to pass
Missing.Value will throw a InvalidCastException (I believe).

In this case, you might want to do some reflection (in the COM sense) on the type library, getting the type, and then looking at the method
information. You should be able to get what you need through the ITypeLib
and ITypeInfo (their .NET counterparts being UCOMITypeLib and UCOMITypeInfo) interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CMan" <cm**@nospam.nospam> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I am trying to use a COM component that has methods with default

parameters.
How can I call these methods from C#. Not all default values are in the
documentation of the control.

Thanks

Colin


Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CMan | last post by:
Hi All, I am trying to use a COM component that has methods with default parameters. How can I call these methods from C#. Not all default values are in the documentation of the control. ...
2
by: Vic Y | last post by:
Hi, I am trying to call a user defined function(UDF) from a stored proc, using a default parameter in the called UDF (e.g. @bid_price_type int = 0 ). However the calling stored proc complains...
2
by: frazer | last post by:
hi, i need to know what interface ms-word's spell checker uses. i got this example from msdn, that makes use of com interop. i was wondering how do i get the interface IMediaContorl or any other...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
3
by: DC Gringo | last post by:
I have an image control (that pulls an image off an ESRI map server): <ASP:IMAGE ID="imgZonedCountry" RUNAT="server"></ASP:IMAGE> In the code behind I am setting the ImageURL to a String value...
1
by: dirk van waes | last post by:
Hello everyone, Being complete newbie in asp.net I am trying to make an example which works with a very simple database. First I made my project in VS- vb.net, draging an oledbconnection and an...
11
by: Greg P | last post by:
I'm using VB 2005, and have drug and dropped datagridviews onto my form. The default code that is generated for inserts tries to insert a value for the auto generated primary key. Below is the...
10
by: =?Utf-8?B?SGVyYg==?= | last post by:
In trying to write VB.Net code to control MSProject 2003 it was recommended that I record a macro in MSProject and transfer the code to VB.Net. When recording the FileSaveAs (to the project server)...
1
by: =?Utf-8?B?UmFq?= | last post by:
I want to understand why C++ interop has better performance than P/Invoke. Can someone explain in detail. Thanks
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.