简体   繁体   English

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

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

I need to embed an API written in C++ in .NET that is used by a Fingerprint device into a .NET application. 我需要在.NET中嵌入用C ++编写的API,指纹设备将其用于.NET应用程序。

I tried with both languages VB.NET and C# but still I'm unable to understand the issue its giving me; 我尝试使用VB.NET和C#两种语言,但我仍然无法理解它给我的问题;

Unable to find the entry point in the DLL.

That means its accessing the DLL, but what is the issue can you please tell me? 这意味着它访问DLL,但是你能告诉我什么问题?

Here is the sample Code: 以下是示例代码:

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();

Thanks @ Hans Passant I have made a research and Use " dumpbin /Exports mydllname.dll " and find the actuall declaration of the functions and that finally works for me. 谢谢@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();

} }

and it works perfectly all right , Thanks for the suggestion. 它完美无瑕,谢谢你的建议。

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

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