473,721 Members | 2,081 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 7996
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
50362
by: Phil Powell | last post by:
<?php class SuperClass { var $mySuperClassVar; function SuperClass($myVar) { $this->mySuperClassVar = $myVar; echo "super class var = $myVar<p>"; }
9
2067
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
3266
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
6105
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
1292
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
6125
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
2272
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
6326
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
8215
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}' That would get me the exact number that I need. Now, I'm trying to do
3
1478
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
8852
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8736
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
9373
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...
0
9227
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8020
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6676
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
4497
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
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3206
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

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.