473,545 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Equivalent of the out c# keyword in C++

Elp
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter
in ordrer to write to this string if an error occurs. That way the calling
program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:

bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++ but
called from C#?

thanks
Nov 16 '05 #1
7 7989
using namespace System::Runtime ::InteropServic es;

bool myFunction([Out] String **error) {}
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:OL******** ******@TK2MSFTN GP11.phx.gbl...
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter
in ordrer to write to this string if an error occurs. That way the calling
program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:

bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++ but called from C#?

thanks

Nov 16 '05 #2
I don't think you can.

"out" is a C#-only construct. It's encoded in the metadata as "ref", with a
custom annotation (attribute, IIRC) that says that it's really an out.

Doing ref in C++ is the best you can do.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:OL******** ******@TK2MSFTN GP11.phx.gbl...
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter
in ordrer to write to this string if an error occurs. That way the calling
program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:

bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++ but called from C#?

thanks

Nov 16 '05 #3
This is not true. Check
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 FEB.1033/vcmex/html/vcconManagedExt ens
ionsForCFrequen tlyAskedQuestio ns.htm, under "Interoperabili ty" -- there's an
item that says "I want to call a Managed Extensions function from C# but not
use a C# ref parameter in the call. How can I specify an out parameter in
Managed Extensions?"

See my earlier post for the solution.
"Eric Gunnerson [MS]" <er****@online. microsoft.com> wrote in message
news:O7******** ******@TK2MSFTN GP11.phx.gbl...
I don't think you can.

"out" is a C#-only construct. It's encoded in the metadata as "ref", with a custom annotation (attribute, IIRC) that says that it's really an out.

Doing ref in C++ is the best you can do.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights. "Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:OL******** ******@TK2MSFTN GP11.phx.gbl...
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter in ordrer to write to this string if an error occurs. That way the calling program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:
bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++

but
called from C#?

thanks


Nov 16 '05 #4
Try something like this:

using namespace System::Runtime ::InteropServic es;

bool myFunction([Out] String** text)
{
*text = "Across The Universe Of Time";
return true;
}

Note that the Managed C++ compiler is unable to check that text is
actually being assigned to. Out is just an attribute and doesn't affect
the generated code (only the metadata).

- Magnus
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:OL******** ******@TK2MSFTN GP11.phx.gbl...
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter
in ordrer to write to this string if an error occurs. That way the calling
program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:

bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++ but called from C#?

thanks

Nov 16 '05 #5
If you are doing this, it should more properly and efficiently be

*text = S"Across The Universe Of Time";

Note the S prefix to make a String literal.
"Magnus Krisell" <ma******@NOSPA Mstudent.liu.se > wrote in message
news:uU******** *****@TK2MSFTNG P11.phx.gbl...
Try something like this:

using namespace System::Runtime ::InteropServic es;

bool myFunction([Out] String** text)
{
*text = "Across The Universe Of Time";
return true;
}

Note that the Managed C++ compiler is unable to check that text is
actually being assigned to. Out is just an attribute and doesn't affect
the generated code (only the metadata).

- Magnus
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:OL******** ******@TK2MSFTN GP11.phx.gbl...
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter in ordrer to write to this string if an error occurs. That way the calling program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:
bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++

but
called from C#?

thanks


Nov 16 '05 #6
> If you are doing this, it should more properly and efficiently be

*text = S"Across The Universe Of Time";

Note the S prefix to make a String literal.


Thanks, I wasn't aware of this.
I should have checked the IL before my posting.

- Magnus
Nov 16 '05 #7
Take a look at this and see if it gives you any ideas.

http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/

Elp wrote:
[Follow-up to microsoft.publi c.dotnet.langag e.vc]

Hi,

I'm developping a small Managed C++ Dll intented to be called from my C#
program. The C++ function should take a reference to a string in parameter
in ordrer to write to this string if an error occurs. That way the calling
program can have info about the error.
If i had to do that in c#, i would have declared my function in this way:

bool myFunction(out string errorMessage) {}

and called it this way:
string error = null;
bool res = myFunction(out error);

How can i do to have the same behaviour if myFunction is in managed C++ but
called from C#?

thanks

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
50349
by: Phil Powell | last post by:
<?php class SuperClass { var $mySuperClassVar; function SuperClass($myVar) { $this->mySuperClassVar = $myVar; echo "super class var = $myVar<p>"; }
9
2053
by: Krishnan | last post by:
Hi, Just curious to know if there's a keyword equivalent to "Myclass" in VB.Net in C# TIA Krishnan
8
3259
by: FDude | last post by:
In otherwords, how do I force a method in my class to call the method implementations in the SAME class and not use any potentially overriden methods in derived classes?
9
6090
by: Chazza | last post by:
I would like to override a method from an inherited class, but the new method has a different signature to the inherited class. Example: class A { private void Init() { // code } } class B : A {
5
1281
by: tlemcenvisit | last post by:
Hello in C# : Partial type definitions allow the definition of a class, struct or interface to be split into multiple files. I'd like to have the equivalent keyword of partial in VC++ does someone has an idea? Thanks in advance
10
6101
by: Bishoy | last post by:
Hi, In VB.NET there is a keyword called "My" which has a lot of properties collected at it. Is there any equivalent to this "My" in C#? Thank you.
12
2245
by: rodchar | last post by:
hey all, vb has a static keyword for variables, what is charp's equivalent,please? static tempVar as String thanks, rodchar
1
6302
by: trialproduct2004 | last post by:
Hi all, can any one tell me use of shadow keyword in vb.net and its equivalent in c# with e.g. Please help me. thanks in advance.
15
8189
by: tereglow | last post by:
Hello all, I come from a shell/perl background and have just to learn python. To start with, I'm trying to obtain system information from a Linux server using the /proc FS. For example, in order to obtain the amount of physical memory on the server, I would do the following in shell: grep ^MemTotal /proc/meminfo | awk '{print $2}' ...
3
1470
by: Friedman, Jason | last post by:
I have lines that look like this: select column1, 'select' as type from table where column2 = 'foo' I want to return: SELECT column1, 'select' AS type FROM table WHERE column2 = 'foo'
0
7490
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
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. ...
0
7935
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
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...
0
6009
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3479
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...
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
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...

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.