我正在尝试创建一个带有几个可导出函数的C# dll。然后,我想让一个C++/非托管程序加载该.dll文件并调用其中特定的导出函数。
我正在使用Robert Giesecke's Unmanaged Exports,但似乎它不起作用。
我在调试器中运行了非托管程序,它成功执行了"LoadLibrary()",但当它尝试"GetProcAddress(test_start)"时,调用失败并返回零。
这是我的C#代码:
.dll编译正常,CPU匹配(x86),但一旦加载了C# DLL,非托管程序就无法获取导出函数地址。目前还比较基础,我只是想让它能够工作。以后我还需要导入。请帮忙解决,因为nuget包的文档相当简单。谢谢。
我正在使用Robert Giesecke's Unmanaged Exports,但似乎它不起作用。
我在调试器中运行了非托管程序,它成功执行了"LoadLibrary()",但当它尝试"GetProcAddress(test_start)"时,调用失败并返回零。
这是我的C#代码:
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
using etc...;
namespace test_dll
{
public class Class1
{
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllExport("test_start", CallingConvention = CallingConvention.Cdecl)]
public static void test_start()
{
MessageBox.Show("It works","YES");
}
}
}
.dll编译正常,CPU匹配(x86),但一旦加载了C# DLL,非托管程序就无法获取导出函数地址。目前还比较基础,我只是想让它能够工作。以后我还需要导入。请帮忙解决,因为nuget包的文档相当简单。谢谢。
GetProcAddress
失败后,GetLastError
返回什么?我假设您正在向GetProcAddress
传递正确的模块句柄。您是否查看了生成的 DLL 的 EXPORTS 部分,以确保test_start
的拼写(包括大小写)与您期望的相同? - Jim MischelDllExport
和构建操作是否已为您导出。 - Peter Duniho