473,396 Members | 1,891 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,396 software developers and data experts.

Call COM object method with optional parameters.

I am trying to convert some vb code calling COM oboject
methods to C#. Example shown as follows

Dim Stream As New ADODB.Stream
Call Stream.Open()

Stream.Open has three optional parameters. I am trying to
convert it to C# as shown as follows

ADODB.Stream Stream = null;
Stream = new ADODB.Stream();
Stream.Open();

Somehow, C# does not like leaving paramters blank. I don't
know how to get around of it. Any help will be
appreciated.

Nov 15 '05 #1
4 3772
Yong,

C# does not support optional parameters, so you are going to have to
pass in a value of Missing for all of the parameters that you do not want to
pass in. In order to do that, you will want to do the following:

// Get a missing value.
object pobjMissing = System.Reflection.Missing.Value;

// Make the call.
ADODB.Stream pobjStream = new ADODB.Stream();
pobjStream.Open(pobjMissing, pobjMissing, pobjMissing, pobjMissing,
pobjMissing);

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

"Yong Jiang" <yj****@yahoo.com> wrote in message
news:03****************************@phx.gbl...
I am trying to convert some vb code calling COM oboject
methods to C#. Example shown as follows

Dim Stream As New ADODB.Stream
Call Stream.Open()

Stream.Open has three optional parameters. I am trying to
convert it to C# as shown as follows

ADODB.Stream Stream = null;
Stream = new ADODB.Stream();
Stream.Open();

Somehow, C# does not like leaving paramters blank. I don't
know how to get around of it. Any help will be
appreciated.

Nov 15 '05 #2
I appreciate your help.

Now I got the following error messages.

Argument '2': convert from 'object'
to 'ADODB.ConnectModeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOpenOptionEnum
Argumetn '4': connot convert from 'object' to 'string'
Argumetn '5': connot convert from 'object' to 'string'

After I changed it to the following to make complier happy

Stream.Open(objMissing, (ADODB.ConnectModeEnum)
objMissing, (ADODB.StreamOpenOptionsEnum) objMissing,
(string) objMissing, (string) objMissing);

I got runtime errors: Specified cast is not valid.

Once again. Thank you for the help.
-----Original Message-----
Yong,

C# does not support optional parameters, so you are going to have topass in a value of Missing for all of the parameters that you do not want topass in. In order to do that, you will want to do the following:
// Get a missing value.
object pobjMissing = System.Reflection.Missing.Value;

// Make the call.
ADODB.Stream pobjStream = new ADODB.Stream();
pobjStream.Open(pobjMissing, pobjMissing, pobjMissing, pobjMissing,pobjMissing);

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

"Yong Jiang" <yj****@yahoo.com> wrote in message
news:03****************************@phx.gbl...
I am trying to convert some vb code calling COM oboject
methods to C#. Example shown as follows

Dim Stream As New ADODB.Stream
Call Stream.Open()

Stream.Open has three optional parameters. I am trying to convert it to C# as shown as follows

ADODB.Stream Stream = null;
Stream = new ADODB.Stream();
Stream.Open();

Somehow, C# does not like leaving paramters blank. I don't know how to get around of it. Any help will be
appreciated.

.

Nov 15 '05 #3
These parameter are optional params but not variants. You will need to pass in an empty string (string.Empty i think) for params 4
and 5 and use the correct enum for 2 and 3. Only param 1 is a variant.

--
Michael Culley
"Yong Jiang" <yj****@yahoo.com> wrote in message news:0e****************************@phx.gbl...
I appreciate your help.

Now I got the following error messages.

Argument '2': convert from 'object'
to 'ADODB.ConnectModeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOpenOptionEnum
Argumetn '4': connot convert from 'object' to 'string'
Argumetn '5': connot convert from 'object' to 'string'

After I changed it to the following to make complier happy

Stream.Open(objMissing, (ADODB.ConnectModeEnum)
objMissing, (ADODB.StreamOpenOptionsEnum) objMissing,
(string) objMissing, (string) objMissing);

I got runtime errors: Specified cast is not valid.

Once again. Thank you for the help.
-----Original Message-----
Yong,

C# does not support optional parameters, so you are

going to have to
pass in a value of Missing for all of the parameters that

you do not want to
pass in. In order to do that, you will want to do the

following:

// Get a missing value.
object pobjMissing = System.Reflection.Missing.Value;

// Make the call.
ADODB.Stream pobjStream = new ADODB.Stream();
pobjStream.Open(pobjMissing, pobjMissing, pobjMissing,

pobjMissing,
pobjMissing);

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

"Yong Jiang" <yj****@yahoo.com> wrote in message
news:03****************************@phx.gbl...
I am trying to convert some vb code calling COM oboject
methods to C#. Example shown as follows

Dim Stream As New ADODB.Stream
Call Stream.Open()

Stream.Open has three optional parameters. I am trying to convert it to C# as shown as follows

ADODB.Stream Stream = null;
Stream = new ADODB.Stream();
Stream.Open();

Somehow, C# does not like leaving paramters blank. I don't know how to get around of it. Any help will be
appreciated.

.

Nov 15 '05 #4
After I used the following statement

Stream.Open(objMissing,
ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecifie d,
string.Empty, string.Empty)

it seems to work fine. I can not use empty string for the
second parameter and third parameter.

Thank you for the help. It is very helpful. Have a very
nice thanks giving.

Yong
-----Original Message-----
These parameter are optional params but not variants. You will need to pass in an empty string (string.Empty i
think) for params 4and 5 and use the correct enum for 2 and 3. Only param 1 is a variant.
--
Michael Culley
"Yong Jiang" <yj****@yahoo.com> wrote in message

news:0e****************************@phx.gbl...
I appreciate your help.

Now I got the following error messages.

Argument '2': convert from 'object'
to 'ADODB.ConnectModeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOpenOptionEnum
Argumetn '4': connot convert from 'object' to 'string'
Argumetn '5': connot convert from 'object' to 'string'

After I changed it to the following to make complier happy
Stream.Open(objMissing, (ADODB.ConnectModeEnum)
objMissing, (ADODB.StreamOpenOptionsEnum) objMissing,
(string) objMissing, (string) objMissing);

I got runtime errors: Specified cast is not valid.

Once again. Thank you for the help.
>-----Original Message-----
>Yong,
>
> C# does not support optional parameters, so you are

going to have to
>pass in a value of Missing for all of the parameters that
you do not want to
>pass in. In order to do that, you will want to do the

following:
>
>// Get a missing value.
>object pobjMissing = System.Reflection.Missing.Value;
>
>// Make the call.
>ADODB.Stream pobjStream = new ADODB.Stream();
>pobjStream.Open(pobjMissing, pobjMissing, pobjMissing,

pobjMissing,
>pobjMissing);
>
> Hope this helps.
>
>
>--
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
>"Yong Jiang" <yj****@yahoo.com> wrote in message
>news:03****************************@phx.gbl...
>> I am trying to convert some vb code calling COM
oboject >> methods to C#. Example shown as follows
>>
>> Dim Stream As New ADODB.Stream
>> Call Stream.Open()
>>
>> Stream.Open has three optional parameters. I am

trying to
>> convert it to C# as shown as follows
>>
>> ADODB.Stream Stream = null;
>> Stream = new ADODB.Stream();
>> Stream.Open();
>>
>> Somehow, C# does not like leaving paramters blank. I

don't
>> know how to get around of it. Any help will be
>> appreciated.
>>
>
>
>.
>

.

Nov 15 '05 #5

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
2
by: Andrew | last post by:
hello, friends, I need to have a few optional parameters in a method of a class and check them if there are any values passed. I know how to do it in VB.net, but I do not know how to do it in...
7
by: Gaetan | last post by:
I would like to extend the capabilities of my application by calling a user method residing in a client provided assembly without having to recompile my application. Things would work like this:...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20...
13
by: =?Utf-8?B?QW5kcmVhcw==?= | last post by:
Hi, I would like to get some thoughts on Overloaded constructors vs. Object initializations. Assuming that the class supports a default constructor, is there any reason to include overloaded...
1
by: mikegolden | last post by:
An application I'm working on makes extensive use of output parameters and return values, thus forcing me to use the ADODB Command object to execute the stored procs. For recordset returning stored...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.