【发布时间】:2017-05-05 06:15:17
【问题描述】:
我正在尝试在 C# 代码中调用 C++ dll。 我的头文件 -
#define MLTtest __declspec(dllexport)
class MLTtest testBuilder
{
public:
testBuilder(void);
~testBuilder(void);
int testfunc (int iNumber);
};
我的 .CPP 课程
int testBuilder::testfunc (int iNumber)
{
return iNumber*2 ;
}
这是我使用该 dll 的 C# 代码。
class Program
{
[DllImport(@"C:\Sources\Operations\Online.Dev\BIN\Debug\Mlt1090d64.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "testfunc")]
public static extern int testfunc(int n);
static void Main(string[] args)
{
try
{
int x = testfunc (50);
}
catch (Exception ex)
{
}
}
}
但我不断收到此异常异常:
无法在 DLL 中找到名为“testfunc”的入口点 'C:\Sources\Operations\Online.Dev\BIN\Debug\Mlt1090d64.dll'。
【问题讨论】:
-
不,这不是我现在编辑的原因。它的复制粘贴错误在这里:)
-
@Adrian 响应是正确的......如果你真的想从 C# 调用 C++(但请注意,它很脆弱,很痛苦,最后它并不是真的有用),见stackoverflow.com/a/42552494/613130