Passing a managed object from C# to CLI by reference

  • Thread starter Thread starter DaTurk
  • Start date Start date
D

DaTurk

This might be a stupid question, but I want to do the equivalent of
passinf an arguement via the "out" keyword in C#, But in CLI. SO I
basically want to pass a managed object from c# into a CLI layer, make
changes to the object in the CLI layer, and have them reflected in the
c# layer. Could someone please show me the syntax to do this?
 
DaTurk said:
I want to do the equivalent of
passinf an arguement via the "out" keyword in C#, But in CLI.

In C++/CLI, you can try this:

void foo([System::Runtime::InteropServices::Out] int% value)

which is equalivalent to the following in C#:

public void foo(out int value)

Another example, this time with a ref class:

void foo([System::Runtime::InteropServices::Out] String^% value)
//C++
public void foo(out string value)
//C#

Tom
 
DaTurk said:
This might be a stupid question, but I want to do the equivalent of
passinf an arguement via the "out" keyword in C#, But in CLI. SO I
basically want to pass a managed object from c# into a CLI layer, make
changes to the object in the CLI layer, and have them reflected in the
c# layer. Could someone please show me the syntax to do this?

Take a look at this page belonging to my friend Tomas Restrepo:

http://www.winterdom.com/cppclifaq/archives/000421.html

Regards,
Will
 
DaTurk said:
This might be a stupid question, but I want to do the equivalent of
passinf an arguement via the "out" keyword in C#, But in CLI. SO I
basically want to pass a managed object from c# into a CLI layer, make
changes to the object in the CLI layer, and have them reflected in the
c# layer. Could someone please show me the syntax to do this?

That doesn't sound like an out parameter at all, it sounds like passing a
managed handle to the C++/CLI code, for which you would use

'MyClass^ paramname'

in the argument list.
 
That doesn't sound like an out parameter at all, it sounds like passing a
managed handle to the C++/CLI code, for which you would use

'MyClass^ paramname'

in the argument list.

THank you, that was alot of help.
 
Back
Top