简体   繁体   中英

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.

I tried with both languages VB.NET and C# but still I'm unable to understand the issue its giving me;

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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