本文介绍了从C#调用C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个简单的例子,我有一个C函数接收一个int,增加并返回递增value.on我进入输入号码文本框对方在C#。我怎么能调用C函数来处理的数量,并从C#回来回来吗?在此先感谢

as a simple example, i have a C function which receives an int,increment it and return incremented value.on the other side I enter the input number to textbox in C#.how can i call C function to process the number and return it back from c#?Thanks in advance

推荐答案

您正在寻找的。

您做将需要引用了System.Runtime.InteropServices 键,然后执行以下操作,如果你的C DLL包含一个名为 increase_int :

You do will need a Reference to System.Runtime.InteropServices and then do the following, if your C DLL contains a function called increase_int:

[DllImport("mylib.dll")]
private static extern int increase_int(int in_value);

和使用它从你的code做

and use it from your code doing

int newValue = increase_int(oldValue);

编辑:该链接指向的实现,因为我已经看到刚才在.NET Compact Framework。该描述也适用于.NET框架。下面是的MSDN杂志更详细的介绍:的http:// MSDN .microsoft.com / EN-US /杂志/ cc164123.aspx MSDN在线:的

The link points to the implementation for the .Net compact framework as I have seen just now. The description also works for the .Net framework. Here is a more detailed intro from MSDN online: https://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

这篇关于从C#调用C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 23:28