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

后端 未结 7 819
长发绾君心
长发绾君心 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:20

    I tested your code and it returns false for me. So there must be something else going on.

    Are you sure you are recompiling the DLL properly? Try deleting the .DLL and doing a rebuild.

    Other than that everything seems to be fine assuming . By default the marshalling will handle the .NET string to const char* without having to decorate it with Marshal attributes, whether the DLL is compiled as ANSI or Unicode.

    See http://msdn.microsoft.com/en-us/library/s9ts558h.aspx#cpcondefaultmarshalingforstringsanchor5

    0 讨论(0)
提交回复
热议问题