gpt4 book ai didi

c# - 如何从 native C(++) DLL 调用 .NET (C#) 代码?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:13:15 25 4
gpt4 key购买 nike

我有一个 C# app.exe 和一个 C# my.dll。 my.dll .NET 项目链接到 native C++ DLL (mynat.dll)(外部 C DLL 接口(interface)),并且从 C# 调用 C++ DLL 没有问题。 (通过使用 [DllImport("mynat.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] 属性。)

我现在需要添加的是让C# dll 提供一些C++ 代码可以调用的回调函数。理想情况下,mynat.dll C++ 代码将使用 LoadLibrary("my.dll") 来加载 C# dll,然后使用 GetProcAddress 来解析它可以调用的回调函数。 (请注意,在 C++ 代码调用 LoadLibrary 时,my.dll C# dll 已加载到进程中 - 此调用只是为了获取 dll 的句柄。)

但是,我不知道从 .NET DLL 导出“外部 C DLL 接口(interface)”的正确方法是什么

我需要做什么才能实现这一目标?

最佳答案

与流行的看法相反,这可能的。
参见 here .

关于c# - 如何从 native C(++) DLL 调用 .NET (C#) 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4737018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com