C# and C++ share memory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Is there any sample codes or documents about how to send and receive the
messages between C++ and C# applications? For instance, I have a C++ dialog
application and C# dialog application running on same computer, how do I
transfer data back and forth between these two?
Thank you very much
Best regards,
Anthony
 
You can create a managed C++ wrapper for your DLL or use COM or use interop
to import DLL functions.
In the latter two cases marshalling will be a big issue and you may have to
create manages structs that mimic the layout of your C++ structs.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Anthony said:
Hi,
Is there any sample codes or documents about how to send and receive the
messages between C++ and C# applications? For instance, I have a C++ dialog
application and C# dialog application running on same computer, how do I
transfer data back and forth between these two?
Thank you very much
Best regards,
Anthony

There are a lot of options you can choose from. Named pipes, shared
memory, DDE, remoting... Depends on your particular need.

Quick googling gave the following:

Named pipes:
http://www.codeproject.com/csharp/DotNetNamedPipesPart1.asp

Named Shared Memory:
http://www.dotnetconsult.co.uk/weblog/permalink.aspx/32c3abfb-bac9-4e19-bbc5-39ca338d906d

DDE:
http://weblogs.asp.net/savanness/archive/2003/12/05/41595.aspx

/Joakim
 
Anthony said:
Hi,
Is there any sample codes or documents about how to send and receive the
messages between C++ and C# applications? For instance, I have a C++
dialog
application and C# dialog application running on same computer, how do I
transfer data back and forth between these two?

You can choose virtually any IPC (interprocess communication) technology
Win32 has. I would probably implement both "ends" in one language (C++), and
use an MC++ wrapper from C#, but you can probably do the same using
P/Invoke.

Have a look at:
http://msdn.microsoft.com/library/d...n-us/ipc/base/interprocess_communications.asp

Assuming the C++ application is managed, you can of course use .NET
remoting.

Niki
 
Back
Top