Managed C++ with .NET Core 2.1

前端 未结 3 979
执笔经年
执笔经年 2021-02-19 18:20

We have a library written in C++. To make it more compatible with our more modern .NET projects, we wrapped this C++ library in another .NET project. It works fine when referenc

3条回答
  •  逝去的感伤
    2021-02-19 18:44

    PInvoke seems to be the only way to go.

    Put the library DLL in the solution folder (the actual C++ DLL, not a .NET wrapper).

    NOTE: Don't reference the DLL in the solution, just place the DLL in the same folder.

    Then use DLL Import to access the methods:

    static class NativeMethods
    {
        [DllImport("MyLibrary.dll", EntryPoint = "ValidateAdminUser", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern Boolean ValidateAdminUser(String username, String password);
    }
    

    NOTE 2: It still requires the .NET Core project to run in x86 architecture.

提交回复
热议问题