繁体   English   中英

如何在VB.NET或C#中使用C ++ API

[英]How to use C++ API in VB.NET or C#

我需要在.NET中嵌入用C ++编写的API,指纹设备将其用于.NET应用程序。

我尝试使用VB.NET和C#两种语言,但我仍然无法理解它给我的问题;

Unable to find the entry point in the DLL.

这意味着它访问DLL,但是你能告诉我什么问题?

以下是示例代码:

internal static class UnsafeNativeMethods
{
    const string _dllLocation = "ABCAPI.dll";
    [DllImport(_dllLocation, EntryPoint = "ABCFunc", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl    )]
    public static extern bool ABCFunc();
}
[System.Runtime.InteropServices.DllImport("ABCAPI.dll", SetLastError = true)]  
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]  
public static extern bool ABCFunc();

谢谢@Hans Passant我做了一个研究并使用“dumpbin / Exports mydllname.dll”并找到函数的实际声明,这最终对我有用。

internal static class UnsafeNativeMethods {
const string _dllLocation = "ABCAPI.dll";
[DllImport(_dllLocation, EntryPoint = "_ABCFunc@4", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.ThisCall    )]
public static extern bool ABCFunc();

}

它完美无瑕,谢谢你的建议。

暂无
暂无

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

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