从 C# 代码使用 C 库
我有一个 C 语言的库。是否可以在 C Sharp 中使用它?
http://zbar.sourceforge.net/ 是我想使用的库的链接
I have a library in C-language. is it possible to use it in C sharp.
http://zbar.sourceforge.net/ is the link of library i want to use
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用平台调用从C# 调用为Windows 编译的C 库。
来自MSDN,进行C函数调用的语法如下:
上面调用了函数Kernel32.dll 中发出蜂鸣声,传入参数频率和持续时间。更复杂的调用可能会传入结构体和指向数组的指针、返回值等...
您需要确保 C 库可用的 C 函数是 适当导出,例如 Beep 函数可能声明如下:
C Libraries compiled for Windows can be called from C# using Platform Invoke.
From MSDN, the syntax of making a C function call is as follows:
The above calls the function Beep in Kernel32.dll, passing in the arguments frequency and duration. More complex calls are possible passing in structs and pointers to arrays, return values etc...
You will need to ensure that the C functions available by the C library are exported appropriately, e.g. the Beep function is likely declared like this:
您可以使用 Swig 为 C 代码创建包装器,以便在 c# 中使用它
You can use Swig to create wrapper for C code in order to use it in c#