[Follow-up to microsoft.public.dotnet.langage.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 7 7987
using namespace System::Runtime::InteropServices;
bool myFunction([Out] String **error) {}
"Elp" <ro********@REMOVEME.hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl... [Follow-up to microsoft.public.dotnet.langage.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
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********@REMOVEME.hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl... [Follow-up to microsoft.public.dotnet.langage.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
This is not true. Check
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vcmex/html/vcconManagedExtens
ionsForCFrequentlyAskedQuestions.htm, under "Interoperability" -- 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**************@TK2MSFTNGP11.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********@REMOVEME.hotmail.com> wrote in message news:OL**************@TK2MSFTNGP11.phx.gbl... [Follow-up to microsoft.public.dotnet.langage.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
Try something like this:
using namespace System::Runtime::InteropServices;
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********@REMOVEME.hotmail.com> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl... [Follow-up to microsoft.public.dotnet.langage.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
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******@NOSPAMstudent.liu.se> wrote in message
news:uU*************@TK2MSFTNGP11.phx.gbl... Try something like this:
using namespace System::Runtime::InteropServices;
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********@REMOVEME.hotmail.com> wrote in message news:OL**************@TK2MSFTNGP11.phx.gbl... [Follow-up to microsoft.public.dotnet.langage.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
> 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
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.public.dotnet.langage.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Powell |
last post by:
<?php
class SuperClass {
var $mySuperClassVar;
function SuperClass($myVar) {
$this->mySuperClassVar = $myVar;
echo "super class var = $myVar<p>";
}
|
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
|
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?
|
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...
|
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...
|
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.
|
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
|
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.
|
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...
|
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'
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
| |