MonoMac 平台与框架的互操作

发布于 2024-12-04 19:02:46 字数 608 浏览 0 评论 0原文

我有使用 DllImport 属性与非托管程序集对话的代码。在 OS X 中,该程序集作为框架安装。

[DllImport("libraryname", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();

然而,这会在 Mono 中抛出 DllNotFoundException,大概是因为它无法解析框架。

我查看了Mono文档: http://www.mono-project.com/Interop_with_Native_Libraries

他们里面有这个小金块:

Mac OS X 平台有一个 lib 前缀和一个 .dylib 后缀,除非 它们是一个框架,在这种情况下它们是一个目录,事情就这样了 更复杂。

但它们不包含任何关于如果它是一个目录我应该做什么的信息(据我所知)。有人有这样做的经验吗?

I have code that uses the DllImport attribute to talk with an unmanaged assembly. In OS X, this assembly is installed as a framework.

[DllImport("libraryname", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();

However, this throws a DllNotFoundException in Mono, presumably because it has not been able to resolve the framework.

I looked in the Mono documentation: http://www.mono-project.com/Interop_with_Native_Libraries

They have this little nugget in there:

Mac OS X platforms have a lib prefix and a .dylib suffix, unless
they're a Framework, in which case they're a directory and things get
more complicated.

But they don't include any info (as far as I could find) about what I should do if it is a directory. Anyone has experience doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

憧憬巴黎街头的黎明 2024-12-11 19:02:46

如果您想与系统框架进行互操作,那么这个解决方案非常简单,因为它的位置永远不会改变。

例如,如果要访问 CoreFoundation 框架中的 CFRelease 函数,请使用:

[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", EntryPoint="CFRelease")]
public static extern void CFRelease(IntPtr cf);

Mono 加载器将毫无问题地加载框架。

This solution is pretty simple if you want to interop with a system framework as its location never changes.

For example, if you want to access the CFRelease function in the CoreFoundation framework, use:

[DllImport("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", EntryPoint="CFRelease")]
public static extern void CFRelease(IntPtr cf);

The Mono loader will load the framework without problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文