By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,962 Members | 2,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,962 IT Pros & Developers. It's quick & easy.

C++ and C#

P: n/a
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

Sep 29 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

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)

ms*****@mail.com wrote:
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
Sep 29 '06 #2

P: n/a
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#.

Chris Fulstow wrote:
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)

ms*****@mail.com wrote:
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
Sep 29 '06 #3

P: n/a
sb*****@gmail.com <sb*****@gmail.comwrote:
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).

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Sep 29 '06 #4

P: n/a
Hi!

Checkout some articles on my page:

http://www.codegod.de/WebAppCodeGod/...ontent=Interop
http://www.codegod.de/WebAppCodeGod/Main.aspx?pid=111
http://www.codegod.de/WebAppCodeGod/Main.aspx?pid=112

--

Bye

Matthias Pieroth
www.codegod.de - The Page for .NET-developers
<ms*****@mail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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

Sep 29 '06 #5

P: n/a
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
Matthias Pieroth wrote:
Hi!

Checkout some articles on my page:

http://www.codegod.de/WebAppCodeGod/...ontent=Interop
http://www.codegod.de/WebAppCodeGod/Main.aspx?pid=111
http://www.codegod.de/WebAppCodeGod/Main.aspx?pid=112

--

Bye

Matthias Pieroth
www.codegod.de - The Page for .NET-developers
<ms*****@mail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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
Oct 18 '06 #6

P: n/a
ms*****@mail.com wrote:
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
Oct 19 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.