如何使用共享内存在两个prgrams(一个在C#中,另一个在C中)之间进行通信 [英] How can I make a communication between two prgrams (one in C# and another one in C) using shared memory

查看:204
本文介绍了如何使用共享内存在两个prgrams(一个在C#中,另一个在C中)之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个程序之间进行通信,一个在C#中,另一个在C中。我有一个用C语言写的服务器,并且正在使用Windows Api函数。

我必须创建应该用C#写的客户。



我尝试了什么:



我已经尝试过使用内存映射文件类,但是id没有用。

我也尝试过使用Windows API函数但是再次没用。

关于最后一次尝试,我想但是我不确定问题应该在参数上,我不知道如何更换HANDLE类型,无效*。

我尝试过来自.Net的IntPtr但它没有用。

有没有办法使这种通信工作但是使用其中一种试验?



谢谢。

I want to make a communication between two programs, one in C# and another one in C. I have the Server which is wrote in C and is using Windows Api functions.
I have to create the Client which should be wrote in C#.

What I have tried:

I already tried using the Memory Mapped File Class, but id didn't worked.
I also tried using the Windows API functions but again it didn't worked.
Regarding the last try, I guess but I am not sure that the problem should be at the paramaters, I don't know how to replace the HANDLE type, the void*.
I tried with IntPtr from .Net but it didn't worked.
Is there a way to make this communication work but using one of this trials?

Thanks.

推荐答案

也许内存映射文件可以帮助你:

C / C ++ - 创建命名共享内存(Windows) [ ^ ]

C# - 内存映射文件 [ ^ ]
Maybe memory-mapped-file can help you here:
C/C++ - Creating Named Shared Memory (Windows)[^]
C# - Memory-Mapped Files[^]


这是一个例子,不是在C但是C ++,使用 gSOAP 来调用WCF服务(可以在C#中):使用gSOAP从Linux C ++客户端调用WCF服务船上代码(旧) [ ^ ]



如果您的应用程序只需要进行本地进程间通信(IPC) )管道是一种快速机制,请参阅CodeProject上的这篇文章:用于Windows中基于管道的IPC的C ++包装器 [ ^ ]
Here is an example, not in C but C++, using gSOAP to call a WCF service (which can be in C#): Calling WCF Services from a Linux C++ Client Using gSOAP | Code On A Boat (Old)[^]

If your applications only need to communicate locally interprocess communication (IPC) with pipes is a fast mechanism, see this article on CodeProject: C++ Wrapper for Pipe-based IPC in Windows[^]


这篇关于如何使用共享内存在两个prgrams(一个在C#中,另一个在C中)之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆