473,842 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 ::InteropServic es::OutAttribut e] 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
5 2682
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 ::InteropServic es::OutAttribut e
On Nov 22, 10:23 am, Cmtk Software <CmtkSoftw...@n ewsgroup.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 ::InteropServic es::OutAttribut e] 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
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 ::InteropServic es::OutAttribut e] 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
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 ::InteropServic es::OutAttribut e] 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
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 ::InteropServic es::OutAttribut e
On Nov 22, 10:23 am, Cmtk Software <CmtkSoftw...@n ewsgroup.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 ::InteropServic es::OutAttribut e] 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
"Cmtk Software" <Cm**********@n ewsgroup.nospam wrote in message
news:05******** *************** ***********@mic rosoft.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 ::InteropServic es::OutAttribut e] 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
9384
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1, 2, func);
15
3501
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here is a small program I wrote to check if I could get the address of the function from the member-function-pointer, so that I could pass it to the function as a normal function-pointer.
9
8259
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a solution? Declaring the function extern "C" fails, because linkage declarations must be made at file scope. #include <stdlib.h> //for qsort template <class T> class Sorter
1
2132
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. The guts will remain in unmanaged c++. So I need to write public managed c++ wrapper classes for the couple of interfaces the unmanaged stuff needs to expose for the GUI. Questions:
7
1863
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has value. It is stored in a member variable in my managed class declared as MyObj __nogc* pMyObj. When I try to retrieve it later, using a function declared as MyObj __nogc* GetObj, the pointer has been corrupted and shows up as <undefined value> when...
5
2314
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or System.CodeDom.CodeCastExpression) __problem typecast #1 Desc:i do needed checks but data/commands in XML is dynamic and i don't wanna fix C# code again and again... Sample:foreach (object some in somearray) (some.GetType())some.someaction();
1
1041
by: Cmtk Software | last post by:
The following code: public __gc class MyClass { public: void MyFunc (int __gc* number); }; Generates the following metadata when compiled in VC 2005 with the /clr:oldsyntax switch in a DLL project:
20
2119
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does not evaluate to a function taking 1 argument.. Here is the smallest code that will not compile: class CTest { void function( char* param ); }; void CTest::function( char* param )
1
2001
by: carled | last post by:
Hi all. New here and new to .net from classic asp. I have to access an xml-rpc webservice in .net and it's making my brain fry trying to get it all set up. I'm most comfortable with vb, but I can translate from c# if anyone can do it in that! I have created a class in my app_code folder that will access the webservice like so: Imports Microsoft.VisualBasic Imports CookComputing.XmlRpc Public Class mapserver Public Structure...
2
2968
by: Bob Altman | last post by:
Hi all, We have a native class modeled after the System::Exception class, and all exceptions that we throw derive from this class. For now this class is quite simple: just Description and InnerException public members. One of these days I'll dig into how to implement a StackTrace property (I assume that this is possible using something like dbghelp.dll, but I've never had the time to look into it). I've recently written a managed...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10674
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5697
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.