By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,728 Members | 1,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,728 IT Pros & Developers. It's quick & easy.

C# Invoking MC++

P: n/a
I have a C# program invoking a MC++ method. One of the output parameters is
an "int".... defined as "int iretval". In the C# program I want to pass the
parameter as either "ref iretval" or "out iretval". In each case..... how
must the corresponding "int" be defined in the MC++ method ?.... so that it
is compile-error free ?

Help ...
--
Philip
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Philip" <ph****@softwareforever.com> wrote in message
news:BC**********************************@microsof t.com...
I have a C# program invoking a MC++ method. One of the output parameters
is
an "int".... defined as "int iretval". In the C# program I want to pass
the
parameter as either "ref iretval" or "out iretval". In each case.....
how
must the corresponding "int" be defined in the MC++ method ?.... so that
it
is compile-error free ?

Help ...
--
Philip


int *iretval

Willy.
Nov 16 '05 #2

P: n/a
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip

"Willy Denoyette [MVP]" wrote:

"Philip" <ph****@softwareforever.com> wrote in message
news:BC**********************************@microsof t.com...
I have a C# program invoking a MC++ method. One of the output parameters
is
an "int".... defined as "int iretval". In the C# program I want to pass
the
parameter as either "ref iretval" or "out iretval". In each case.....
how
must the corresponding "int" be defined in the MC++ method ?.... so that
it
is compile-error free ?

Help ...
--
Philip


int *iretval

Willy.

Nov 16 '05 #3

P: n/a
Sorry, we are talking IJW. Enter the unsafe context....

C#
int i;
unsafe {c.ModInt(&i);}

C++
void ModInt(int* i)
{
*i = 123;
}

Willy.
"Philip" <ph****@softwareforever.com> wrote in message
news:E3**********************************@microsof t.com...
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip

"Willy Denoyette [MVP]" wrote:

"Philip" <ph****@softwareforever.com> wrote in message
news:BC**********************************@microsof t.com...
>I have a C# program invoking a MC++ method. One of the output
>parameters
>is
> an "int".... defined as "int iretval". In the C# program I want to
> pass
> the
> parameter as either "ref iretval" or "out iretval". In each case.....
> how
> must the corresponding "int" be defined in the MC++ method ?.... so
> that
> it
> is compile-error free ?
>
> Help ...
>
>
> --
> Philip


int *iretval

Willy.

Nov 16 '05 #4

P: n/a
Or:
C#
unsafe {
c.ModInt(&i);
...
C++
void ModInt(int& i)
{
i = 123;
}

Willy.

"Philip" <ph****@softwareforever.com> wrote in message
news:E3**********************************@microsof t.com...
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip

"Willy Denoyette [MVP]" wrote:

"Philip" <ph****@softwareforever.com> wrote in message
news:BC**********************************@microsof t.com...
>I have a C# program invoking a MC++ method. One of the output
>parameters
>is
> an "int".... defined as "int iretval". In the C# program I want to
> pass
> the
> parameter as either "ref iretval" or "out iretval". In each case.....
> how
> must the corresponding "int" be defined in the MC++ method ?.... so
> that
> it
> is compile-error free ?
>
> Help ...
>
>
> --
> Philip


int *iretval

Willy.

Nov 16 '05 #5

P: n/a

"Philip" <ph****@softwareforever.com> wrote in message
news:E3**********************************@microsof t.com...
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip


Or in a "safe" context:

C#
c.ModInt(ref i);

C++
1)
void ModInt3(System::Int32& i)
{
i = 13;
}

2)
void ModInt3(System::Int32* i)
{
*i = 13;
}

That's all I can think about.
Note that if you pass anything that is not stack allocated to unmanaged code
you need to pin the variable..

Willy.
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.