Passing a managed object from C# to CLI by reference

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?
 
T

Tamas Demjen

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
 
W

William DePalo [MVP VC++]

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
 
B

Ben Voigt [C++ MVP]

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.
 
D

DaTurk

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top