C++ and C#

M

mshetty

Hi,

We have some common functionality that has to run with both C++ and C#.
What would be the best way to design this.

One of the approaches we could think of is to
1. create an exe for the common code
2. create api's in C++ and C# to invoke this exe
3. Put the api's in a library each for C# and C++

Would help if we could get some alternatives to do this.

Is it possible to directly link/use code compiled with a C++ with C#?

Thanks and Regards,
M Shetty
 
C

Chris Fulstow

You could put your code in an unmanaged DLL, then use platform invoke
to call it from your C# assembly and call it natively from C++.

Or, you could create a COM interface for your code, which could then be
called from C++ or C# (using COM interop, i.e. TlbImp.exe)
 
S

sbarlea

The best way yo do this is, i think this:
1. Create the C++ stuff like you normally would.
2. Create a Managed Wrapper using Managed C++ around your unmanaged
functions.
3. Use the wrapper in C#.
 
T

Thomas T. Veldhouse

The best way yo do this is, i think this:
1. Create the C++ stuff like you normally would.
2. Create a Managed Wrapper using Managed C++ around your unmanaged
functions.
3. Use the wrapper in C#.

I agree ... although writing the interfaces and C++ with ATL/COM is much
easier to consume in C#, so if the skills are there to do this, it is probably
the easier solution (with COM, you get connection points converted to
delegates and events for free as an example).
 
M

mshetty

Hi,

Thanks a lot for the response.

I have been able to do something..

Having some problems, unable to pass a string stored in a "string" from
C# to a std::string in C++.

Can pass the string to a char * though..

Any idea on how it can be done with std::string?

Thanks and Regards,
M Shetty
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Having some problems, unable to pass a string stored in a "string" from
C# to a std::string in C++.

Can pass the string to a char * though..

Any idea on how it can be done with std::string?

Considering that a char* can be assigned to a string, then
why bother ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top