Calling mangled non-managed C++ DLL function in C#

55 views Asked by At

For some reasons, I have to create a C++ DLL file containing functions with __stdcall calling convention.

namespace NS
{
    __declspec(dllexport) std::string __stdcall Function(int Num);
}

To be able to use it in C#, I did this way:

[DllImport("mydll.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "?Function@NS@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z"]
static extern String Function(int Num);

The EntryPoint string was obtained with DUMPBIN. When I run the application, I get the error Unable to find an entry point named '?' in DLL 'mydll.dll'.

Both C++ and C# applications were constructed with Visual Studio 2020 in x64 Debug mode.

Can someone suggest how to fix the problem?

Note-> I did not use extern "C" to be able to use std::string and std::vector

0

There are 0 answers