我正在尝试使用Robert Giesecke的“UnmanagedExports”nuget包创建一个C#非托管DLL,但它似乎没有创建任何入口点。
完整代码:
using System.IO;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
namespace ImpactHive
{
internal static class Main
{
[DllExport("_RVExtension@12", CallingConvention = CallingConvention.StdCall)]
static void RVExtension(out char output, int outputSize, char function)
{
using (StreamWriter writer = new StreamWriter(@"C:\dll_log.txt"))
{
writer.WriteLine("It works!");
writer.WriteLine(function);
}
output = function;
}
}
}
我做错了什么?
澄清:
这是一个extension DLL for Arma 3,需要一个名称为“_RVExtension@12
”且带签名的入口点:
void __stdcall RVExtension(char *output, int outputSize, const char *function);
编辑:我已在项目设置中将目标平台指定为x86,但没有运气。
答案 0 :(得分:1)
事实证明[DllExport]
属性完全符合预期。
我遇到的问题是C#中没有本地[DllExport]
属性的原因之一 - Dll的调用者必须加载.net框架才能让C#dll显示该条目指向它。
问题是我用来检查公开的入口点的应用程序没有加载.net框架,因此没有报告入口点。
通过打开VS2013的开发人员命令提示符并运行返回以下内容的dumpbin /exports "C:\myDllName.dll"
确认了这一点:
Dump of file C:\myDllName.dll
File Type: DLL
Section contains the following exports for \myDllName.dll
00000000 characteristics
54F6EC86 time date stamp Wed Mar 04 11:29:10 2015
0.00 version
0 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
0 0 000028CE _RVExtension@12
Summary
2000 .reloc
2000 .rsrc
2000 .sdata
2000 .text
清楚地显示公开的入口点......
这意味着我无法将此dll用于我的扩展,因为Arma 3游戏引擎默认不加载.net框架,因此无法调用我的C#dll。