[英]No functions in C# DLL with RGiesecke.DllExport
我正在尝试在C#中创建一个DLL,以便在其他几种语言中使用。 我找到了RGiesecke的DllExport,但似乎没有用。 它构建得很好并且创建了一个dll,但是当我在Dependency Walker中打开它时它没有显示任何函数,我的调用代码也找不到它们。
我创建了一个新的“类库”项目(VS 2013),然后从NuGet安装了“Unmanaged Exports(DllExport for .Net)”。 我需要任何项目设置吗?
这是我的代码。
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
namespace ToolServiceDLL
{
public class Class1
{
[DllExport("addUp", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static double addUp(double num1, double num2)
{
return num1 + num2;
}
[DllExport("get5", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int get5()
{
return 5;
}
}
}
我发现了这个问题。 它在RGiesecke文档中有它,但我错过了它。 在项目设置 - >构建 - >平台目标中:您不能将其设置为“任何CPU”。 您必须将其设置为x64或x86,具体取决于您是否要在64位或32位应用程序中使用它。
我有类似的问题,但已经将平台目标设置为x64并出现以下错误:
The name 'CallingConvention' does not exist in the current context
我发现添加using指令System.Runtime.InteropServices
解决了这个问题。
这是一个很好的问题,对我有用。 由于我犯了一个错误的Python方面,只花了不少时间。 这是Python3中的工作代码import sys import clr sys.path.insert(0,'C:\\\\your_path\\\\Py2NetComm\\\\bin\\\\Debug') clr.AddReference("Py2NetComm") import ToolServiceDLL as p2n ret = p2n.Class1.addUp(2,3) print("addUp:", ret)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.