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
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...
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...
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...
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...
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...
I am using Beta 2 and it works.
Thanks!
"Ronald Laeremans [MSFT]" <ronl...@microsoft.com> wrote in message
news:OwutK1HaBHA.2064@tkmsftngp03...