C API到C#GUI

编程入门 行业动态 更新时间:2024-10-13 06:18:30
本文介绍了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

本文发布于:2023-11-12 11:03:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:API   GUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!