473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to use the return value when using C# dlls in a C++ project?

hi,

I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-getResult();

std::string str; // here I want to copy result to str, then I can use
the string freely. But I don't know how to do it.

Is there any way ?

Thanks!

Jul 26 '07 #1
3 3214
Vivienne wrote:
I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-getResult();

std::string str; // here I want to copy result to str, then I can use
the string freely. But I don't know how to do it.

Is there any way ?
You need to ask in a C# forum. See 'microsoft.pulbic.dotnet.*'
hierarchy of newsgroups.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '07 #2
On Jul 26, 3:01 pm, Vivienne <zhoudan.b...@gmail.comwrote:
hi,

I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-getResult();

std::string str; // here I want to copy result to str, then I can use
the string freely. But I don't know how to do it.

Is there any way ?

Thanks!
AFAIK you have to grub about getting the internal representation of
the System::String and cons a std::string from that. It's awkward but
a solved problem - MSDN will tell you how.

Jul 26 '07 #3
Vivienne <zh**********@gmail.comwrote:
I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-getResult();

std::string str; // here I want to copy result to str, then I can use
the string freely. But I don't know how to do it.

Is there any way ?
What you need to do is "marshal" the string. Here are two articles that
give sample code:

http://msdn2.microsoft.com/en-us/lib...23(vs.80).aspx
http://blogs.msdn.com/slippman/archi...02/147090.aspx

For any further questions, please consult a C# newsgroup.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 26 '07 #4

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

Similar topics

4
by: Derrick | last post by:
Long story short: I've been working on a project which includes both designtime and runtime components, for both the PC and Pocket PC. While testing, I've been having problems with Visual Studio...
2
by: Johann Blake | last post by:
I can hardly believe I'm the first one to report this, but having gone through the newsgroup, it appears that way. I would like to open a solution in the VS.NET IDE that consists of multiple...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
2
by: | last post by:
I try to build dll in VC .NET, In that project I use dlls that were built in VC6, and I get a lot of errors. (for example <iostream.h> instead of <iostream> etc.) I am not aloud to change anything...
1
by: Hughsie | last post by:
Hi I have created an installation package for my app and I have installed the application onto another machine together with the framework and the correct MDAC version. The problem is when I...
1
by: Thomas D. | last post by:
Hello all, I'm using the IXmlSerializable interface for a project and encounter some problems when testing my webservice in a client application. I know this interface is undocumented and not...
6
by: tony | last post by:
Hello! I have several projects where each one build a library.(class library or window control library). Now I get some strange compile error when building the *.exe file and doesn't...
7
by: Olegus | last post by:
Hello, in order to perform backup/restore MSSQL database using SMO, one needs to reference several namespaces in a backup class : using Microsoft.SqlServer.Management.Common; using...
10
by: Phil | last post by:
VB2005 Express. I am developing a solution that involves a windows forms application and a number of class library projects (DLLs). Some of the DLLs require extra data files or third party dlls. I...
0
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,...
0
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...
0
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...
0
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
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.