title: C# DllImport with C++ boolean function not returning correctly
body: <p>I have the following function in a C++ DLL</p>
  
  <pre><code>extern "C" __declspec(dllexport) bool Exist(const char* name)
  {
   //if (g_Queues.find(name) != g_Queues.end())
   // return true;
   //else
   // return false;
   return false;
  }
  </code></pre>
  
  <p>Inside my C# class I have the following:</p>
  
  <pre><code>[DllImport("Whisper.dll", EntryPoint="Exist", CallingConvention=CallingConvention.Cdecl)]
          public static extern bool Exist(string name);
  </code></pre>
  
  <p>Yet, whenever I call my function it ALWAYS returns true, even when I commented out my little function and made it return false. I have the feeling there is something wrong with my calling convention or any other issue with P/Invoking my DLL, probably corresponding with the string and const char*, but for now I am completely clueless. What am I doing wrong? Why does it return true instead of false?</p>
  
  <p><em><strong>EDIT:</em></strong> I have figured out this has nothing to do with the const char* or string, because the problem persists with an empty function. I've tried changing the calling convention between Cdecl and StdCall and neither work correctly. I've also managed to debug my DLL and it's being called correctly and does indeed return false, but once back into C# it somehow is true. Changing the CharSet also had no effect. I've made sure I've supplied my C# program with the latest and correct version of my DLL each time, so that shouldn't be an issue aswell. Again, I am completely clueless on why the result is true when I'm in fact returning false.</p>
  
  <p><em><strong>EDIT2:</em></strong> SOReader provided me with a suggestion which fixes another important issue, see my comment. Sadly, it does not fix the return issue.</p>
  
  <p><em><strong>EDIT3:</em></strong> I have concluded that changing the return type of Exist (bool) into (int) suddenly makes it return the correct number (true = 1, false = 0). That would mean that there may be an issue between C++'s bool and C#'s bool. I can continue using an int as a bool, but that would still not explain the original problem. Maybe somebody else can enlighten me on this one? Perhaps it has to do with the fact that I'm using x64 (although both pojects are compiled as x86)</p>