C API到C#GUI [英] C api to C# GUI

查看:190
本文介绍了C API到C#GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节流,我有点为结构。现在我需要更新使用从这些结构值的C#GUI。现在,我已经发现了大约的PInvoke和dllimport的使用谷歌,但一切都从C#调用C代码的东西,我需要做的是相反的。

I have a stream of bytes that I sort into structs. Now I need to update a C# GUI using values from those structs. Now I've found things about pinvoke and dllimport using Google but everything is calling c code from c#, I need to do the opposite.

C#代码具有函数旋表盘/更新值,所以一旦我有我需要我只想调用这些函数,这些值作为参数的值,我的C代码全部编写,而且GUI所有的编码和功能的使用,我和我的鼠标拖动刻度盘,我只需要粘合在一起这些。

The c# code has functions that spin dials/updates values, so once I have the values I need I want to just call those functions, with those values as parameters, my c code is all written and the gui is all coded and functional using dials that I drag with my mouse, I just need to glue these together.

感谢您的帮助!

推荐答案

一般来说,你不能调用C代码C#代码。 (您可以调用的的到C代码C#代码,但C#端需要启动进程并传递一个回调。)

Generally speaking, you cannot call C# code from C code. (You can call back into C# code from C code, but the C# side needs to initiate the process and pass in a callback.)

正道是C#代码调用到C代码,并提供一个回调函数(查找的 UnmanagedFunctionPointer 属性,如何把管理委托到函数指针。)

The "right way" is for the C# code to call into the C code and provide a callback function (look up the UnmanagedFunctionPointer attribute for how to turn a managed delegate into a function pointer.)

如果该选项ISN 'T有可能,你有几个选择,但没有人将要像刚才一样方便起来粘合事:

If that option isn't possible, you have a few alternatives, but none of them are going to be as easy as just "gluing thing together":


  • 使用混合模式的C ++库来弥补C和C#代码。这是一个烂摊子,国际海事组织,我只有它建议,因为它的变化最少的C代码。

  • 从C#代码暴露一个COM对象,并与来自C.沟通稍显不足的选项A,但在COM引入到组合的成本少凌乱。

  • 使用某种形式的进程间通信(TCP套接字,命名管道等)和之间进行通信两个代码元素如同它们是独立的程序。

这篇关于C API到C#GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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