Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Out parameters for member of managed class

0 views
Skip to first unread message

Dmitry

unread,
Oct 27, 2001, 2:52:57 PM10/27/01
to
Hello,

Could you please tell me how to convert this C# code to MC++

void Func1(out int param1, out int param2, out int param3) {

param1 = 1;
param2 = 2;
param3 = 3;
}

void Func2() {
int arg1;
int arg2;
int arg3;

Func1(out arg1, out arg2, out arg3);
}

Best regards
Dmitry


Ulzii

unread,
Oct 27, 2001, 4:39:56 PM10/27/01
to
Hi Dmitry,

As I recall in C# out parameters are just like ref parameters. Here's a
direct quote from a book by Eric Gunnerson, "A Programmer's Introduction to
C#",
"From the perspective of other .NET languages, there is no difference
between ref and out parameters. A C# program calling this function will see
the parameters as out parameters, but other languages will see them as ref
parameters."

Hence, the code converted to MC++ would look like:

void Func1(Int32 __gc* param1, Int32 __gc* param2, Int32 __gc* param3) {

(*param1) = 1;
(*param2) = 2;
(*param3) = 3;
}

void Func2() {
Int32 arg1;
Int32 arg2;
Int32 arg3;

Func1(&arg1, &arg2, &arg3);
}

Ulzii-

"Dmitry" <c...@mail.ru> wrote in message news:#iUp5jxXBHA.2176@tkmsftngp03...

Dmitry

unread,
Oct 28, 2001, 11:37:11 AM10/28/01
to
Hello,

Thank you for your answer.

But in this case parameters are ref but not out. If Func2 is called from
MC++ there are no problems but if I need to call it from C# it is not
convenient
as argument should be obligatory initialized. It is the most critical for
"out System.Object" parameters.

I couldn't use in C#

void Func2() {
int arg1;
int arg2;
int arg3;

Func1(out arg1, out arg2, out arg3);
}

I should use instead

void Func2() {
int arg1 = 0;
int arg2 = 0;
int arg3 = 0;

Func1(ref arg1, ref arg2, ref arg3);
}

May be you know if MC++ supports out parameters in meaning of .Net or only
ref.

Best regards
Dmitry

"Ulzii" <ba...@microsoft.com> wrote in message
news:eIDfflyXBHA.2040@tkmsftngp05...

Jeff Peil [MSFT]

unread,
Oct 28, 2001, 7:07:47 PM10/28/01
to
Dmitry,

If you attribute the parameters with [System::Runtime::InteropServices::Out]
C# will see them as out parameters.


"Dmitry" <c...@mail.ru> wrote in message news:OZWkM78XBHA.2080@tkmsftngp03...

Jo

unread,
Nov 8, 2001, 9:28:08 AM11/8/01
to
Do you mean attribute the C++ parameter declaration. If I do it, I get an
error telling me that
error C3108: 'out' : this attribute may not be used in a managed context

if I specify the out parameter in the C# call, I get:
Argument '3': cannot convert from 'out int' to 'ref int'

So, I have to initialize the out parameter prior to call my function and
consider it as a ref parameter.

Is there a way to declare the C++ method in order to have out parameter ?

"Jeff Peil [MSFT]" <jp...@bigfoot.com> wrote in message
news:#AzZG3AYBHA.1712@tkmsftngp05...

Ronald Laeremans [MSFT]

unread,
Nov 8, 2001, 12:46:00 PM11/8/01
to
Are you using the attribute
[System::Runtime::InteropServices::Out]
and NOT the attribute
[out]?

If so, it should definitely work in RC1, and I think it did work in Beta 2,
but I am not certain about the latter. What version of the compiler are you
using?

Ronald Laeremans
Visual C++ compiler team


"Jo" <jg...@hotmail.com> wrote in message
news:uzXgeGGaBHA.1452@tkmsftngp04...

Jo

unread,
Nov 8, 2001, 1:21:28 PM11/8/01
to
Sorry, my mistake. I used [out] instead of [Out].

I am using Beta 2 and it works.

Thanks!

"Ronald Laeremans [MSFT]" <ronl...@microsoft.com> wrote in message
news:OwutK1HaBHA.2064@tkmsftngp03...

0 new messages