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

Defining a managed member function which takes a “ref” param

P: n/a
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);
};

Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);
}

I’d like to use C++/CLI’s new syntax and declare a “ref class”.
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as “ref” in the metadata.
I tried using the “int^” definition but it’s not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the “out” for the
number param.

What’s the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.

Nov 22 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
this is the C# newsgroup and thus the wrong one for your question

but you use

int% number

for a ref parameter and

[Out]int% number

for a out parameter

where Out is System::Runtime::InteropServices::OutAttribute
On Nov 22, 10:23 am, Cmtk Software <CmtkSoftw...@newsgroup.nospam>
wrote:
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);

};Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);

}I'd like to use C++/CLI's new syntax and declare a "ref class".
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as "ref" in the metadata.
I tried using the "int^" definition but it's not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the "out" for the
number param.

What's the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.
Nov 22 '06 #2

P: n/a
Have you tried applying the in and out attributes to get a ref?

Ciaran O'Donnell

"Cmtk Software" wrote:
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);
};

Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);
}

I’d like to use C++/CLI’s new syntax and declare a “ref class”.
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as “ref” in the metadata.
I tried using the “int^” definition but it’s not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the “out” for the
number param.

What’s the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.
Nov 22 '06 #3

P: n/a
If not that, try:
public __gc class MyClass
{
public:
void MyFunc (int __gc*& number);
};
Ciaran O'Donnell
"Cmtk Software" wrote:
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);
};

Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);
}

I’d like to use C++/CLI’s new syntax and declare a “ref class”.
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as “ref” in the metadata.
I tried using the “int^” definition but it’s not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the “out” for the
number param.

What’s the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.
Nov 22 '06 #4

P: n/a
Dear Simon,

Sorry for the misplacement.

The % operator solved my problem.

Thanks a bunch!

"Simon Dahlbacka" wrote:
this is the C# newsgroup and thus the wrong one for your question

but you use

int% number

for a ref parameter and

[Out]int% number

for a out parameter

where Out is System::Runtime::InteropServices::OutAttribute
On Nov 22, 10:23 am, Cmtk Software <CmtkSoftw...@newsgroup.nospam>
wrote:
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);

};Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);

}I'd like to use C++/CLI's new syntax and declare a "ref class".
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as "ref" in the metadata.
I tried using the "int^" definition but it's not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the "out" for the
number param.

What's the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.

Nov 22 '06 #5

P: n/a
"Cmtk Software" <Cm**********@newsgroup.nospamwrote in message
news:05**********************************@microsof t.com...
The following code:

public __gc class MyClass
{
public:
void MyFunc (int __gc* number);
};

Generates the following metadata for C# when compiled in VC 2005 with the
/clr:oldsyntax switch in a DLL project:

public class MyClass
{
public MyClass();

public void MyFunc(ref int number);
}

I’d like to use C++/CLI’s new syntax and declare a “ref class”.
I could not find the appropriate CLI syntax for declaring a function
parameter, which will appear as “ref” in the metadata.
I tried using the “int^” definition but it’s not possible to call this
function from C# and pass it a variable by reference.
I also tried using the [System::Runtime::InteropServices::OutAttribute] but
the function declaration in the metadata appears without the “out” for the
number param.

What’s the correct CLI syntax for defining a "ref"/"out" function parameter?

Thanks in advance.

Please post C++ related questions to the VC NG, and you might save considrable time when
consulting the documentation before posting.

http://msdn2.microsoft.com/en-us/library/6f63s5b1.aspx

Willy.

Nov 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.