Calling UNIX and Linuxshared object file.so from c#(从 c# 调用 UNIX 和 Linux 共享对象文件 .so)
问题描述
有没有办法从 C# P/Invoke 调用用 C 编写并在 Unix 上构建的共享对象文件?
Is there a way for a Shared Object file written in C and built on Unix to be called from C# P/Invoke?
或者我需要使用 Java 或类似的东西吗?
Or do I need to use Java or something like that?
推荐答案
Mono 能够从基于 dlopen(3) 构建的 C# 中与本地库集成.您只需使用带有库名称的 DllImport 语句(即libform.so.5"),然后使用友好的 C# 类来包装本机代码和数据类型,该类负责处理所有低级内容.此页面 有一个很好的概述,其中包含有关如何处理封送指针和其他不安全类型的大量信息.
Mono has the ability to integrate with native libraries from within C# built on top of dlopen(3). You just have to use the DllImport statement with the name of the library (i.e. 'libform.so.5'), then wrap the native code and data types with a friendly C# class that takes care of all the low-level stuff. This page has a good overview with lots of information on how to deal with marshaling pointers and other unsafe types.
一旦你编写了你的包装类,你就可以直接使用它,而不必担心它在下面使用了一个本地共享库.
Once you've got your wrapper class written, you can just use that without worrying about the fact that it's using a native shared library underneath.
这篇关于从 c# 调用 UNIX 和 Linux 共享对象文件 .so的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 c# 调用 UNIX 和 Linux 共享对象文件 .so
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
