473,769 Members | 8,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3792
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.Reflecti on.Missing.Valu e;

// 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.co m

"Yong Jiang" <yj****@yahoo.c om> 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.ConnectM odeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOp enOptionEnum
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(obj Missing, (ADODB.ConnectM odeEnum)
objMissing, (ADODB.StreamOp enOptionsEnum) 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.Reflecti on.Missing.Valu e;

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

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

"Yong Jiang" <yj****@yahoo.c om> 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.c om> 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.ConnectM odeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOp enOptionEnum
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(obj Missing, (ADODB.ConnectM odeEnum)
objMissing, (ADODB.StreamOp enOptionsEnum) 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.Reflecti on.Missing.Valu e;

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

pobjMissing,
pobjMissing) ;

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

"Yong Jiang" <yj****@yahoo.c om> 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(obj Missing,
ADODB.ConnectMo deEnum.adModeUn known,
ADODB.StreamOpe nOptionsEnum.ad OpenStreamUnspe cified,
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.c om> 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.ConnectM odeEnum'
Argument '3': convert from 'object'
to 'ADODB.StreamOp enOptionEnum
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(obj Missing, (ADODB.ConnectM odeEnum)
objMissing, (ADODB.StreamOp enOptionsEnum) 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.Reflecti on.Missing.Valu e;
>
>// Make the call.
>ADODB.Stream pobjStream = new ADODB.Stream();
>pobjStream.Ope n(pobjMissing, pobjMissing, pobjMissing,

pobjMissing,
>pobjMissing) ;
>
> Hope this helps.
>
>
>--
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard. caspershouse.co m
>
>"Yong Jiang" <yj****@yahoo.c om> 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
6703
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 Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
5
2970
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 problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
26
21341
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
1270
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 VC++.net. Probably it is easy, but could anyone help me with a sample source code or reference paper for a method that allows optional parameters? Thanks a lot.
7
2042
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: 1- Read a configuration file where the client provides the assembly name (DLL) and the method name. 2- Detect the existence of the assembly file.
12
2673
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 avoided. I'd like to hear your various opinions on this matter.
1
2467
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 different fields that are optional per measure. How do I account for the different fields that will be posted from the different forms when I create the measure object? Should I create a constructor method with just the required fields as the...
13
1519
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 constructors when you are able to use object initialization? I see a point, to provide the overloads, if you are developing framework code that might support the need to run ontop of 2.x but if you are writing a sealed application / know you are...
1
7202
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 procs, calling Execute() is no problem using JavaScript: var rs = cmd.Execute(); However, for non-recordset returning stored procs -- and this app has many -- I need to call Execute() passing adExecuteNoRecords for the Options parameter,...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.