C# DllImport with C++ boolean function not returning correctly

后端 未结 7 840
长发绾君心
长发绾君心 2020-11-29 04:20

I have the following function in a C++ DLL

extern \"C\" __declspec(dllexport) bool Exist(const char* name)
{
 //if (g_Queues.find(name) != g_Queues.end())
 /         


        
7条回答
  •  时光说笑
    2020-11-29 05:15

    Perhaps marshaling the argument of the function might help:

    [MarshalAs(UnmanagedType.LPStr)]
    

    Here is how the declaration should look like:

    [DllImport("Whisper.dll", EntryPoint="Exist", CallingConvention=CallingConvention.Cdecl)]
            public static extern bool Exist([MarshalAs(UnmanagedType.LPStr)] string name);
    

提交回复
热议问题