繁体   English   中英

C#:DLLImport-找不到DLL异常

[英]C# : DLLImport - DLL Not Found exception

假设我想从ac#代码中调用c ++函数,遇到以下问题:

情况1:

class abc
{
private :
    int a ;

public :
    int  getValue()
    {
        return 100;
    }
};

int GetCounter()
{
    abc* p = new abc();

    int i = p->getValue();
    return i;
}

从C#调用函数时,这种情况会抛出DLL找不到异常。

情况2:

int GetCounter()
{
    int i = 333;
    return i;
}

从C#调用函数的情况很好。

有什么想法吗? 我该如何解决?

在CPP项目(MathFuncsDll.h)中使用此示例代码行

extern "C" __declspec(dllexport) double Add(double a, double b);
extern "C" __declspec(dllexport) double Sub(double a, double b);
extern "C" __declspec(dllexport) double Mul(double a, double b);
extern "C" __declspec(dllexport) double Div(double a, double b);

在C#代码中使用像这样

 [DllImport("MathFuncs.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern Double Add(Double a, Double b);

 [DllImport("MathFuncs.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern Double Mul(Double a, Double b);

 [DllImport("MathFuncs.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern Double Sub(Double a, Double b);

 [DllImport("MathFuncs.dll",CallingConvention = CallingConvention.Cdecl)]
 public static extern Double Div(Double a, Double b);

 [DllImport("MathFuncs.dll",CallingConvention = CallingConvention.Cdecl)]
 public static extern Double Bat(Double a, Double b);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM