假设您有以下C++代码:
extern "C" {
void testA(int a, float b) {
}
static void testB(int a, float b){
}
}
Run Code Online (Sandbox Code Playgroud)
我想在我的C#项目中使用DllImport以下方法访问它:
class PlatformInvokeTest
{
[DllImport("test.so")]
public static extern void testA(int a, float b);
[DllImport("test.so")]
internal static extern void testB(int a, float b);
public static void Main()
{
testA(0, 1.0f);
testB(0, 1.0f);
}
}
Run Code Online (Sandbox Code Playgroud)
这非常适用testA,但testB无法抛出EntryPointNotFoundException.
我可以testB从我的C#代码访问吗?怎么样?
我尝试在我的c#控制台应用程序中绑定http://msdn.microsoft.com/en-us/library/ms235636.aspx中显示的简单c ++ dll ,但是在运行时我在dll中得到了一个EntryPointNotFoundException.我的测试课是
namespace BindingCppDllExample
{
public class BindingDllClass
{
[DllImport("MathFuncsDll.dll")]
public static extern double Add(double a, double b);
}
public class Program
{
public static void Main(string[] args)
{
double a = 2.3;
double b = 3.8;
double c = BindingDllClass.Add(a, b);
Console.WriteLine(string.Format("{0} + {1} = {2}", a, b, c));
}
}
}
Run Code Online (Sandbox Code Playgroud)
什么是不正确的?
在我的应用程序中,我有一个实用程序类,它应该并行执行一系列任务,并提供有关各种任务的成功和时间的报告.
每次运行它时,我都会得到一个EntryPointNotFoundException.
我能想出的最简单的测试案例创造了这种行为,这是无关紧要的.只是
Task.Run(() => { Console.WriteLine("This is sanity test"); });
Run Code Online (Sandbox Code Playgroud)
不使用返回值,并且任何地方都没有自定义类抛出EntryPointNotFoundException.
这是在Visual Studio 2015中,该过程是64位(对于整个应用程序,它必须在Windows 7 64位上运行).它是一个.NET 4.5控制台应用程序.
是什么导致这种情况以及如何解决?