title: PInvoke Unbalances the stack
body: <p>Good afternoon,</p>
  
  <p>I have been working on a dll that can use CORBA to communicate to an application that is network aware.  The code works fine if I run it as a C++ console application.  However, I have gotten stuck on exporting the methods as a dll.  The methods seems to export fine, and if I call a method with no parameters then it works as expected.  I'm hung up on passing a C# string to a C++ method.</p>
  
  <p>My C++ method header looks like this:</p>
  
  <pre><code>bool __declspec(dllexport) SpiceStart(char* installPath)
  </code></pre>
  
  <p>My C# DLL import code is as follows:</p>
  
  <pre><code>[DllImportAttribute("SchemSipc.dll", CharSet=CharSet.Ansi)]
  private static extern bool SpiceStart(string installPath);
  </code></pre>
  
  <p>I call the method like so:</p>
  
  <pre><code>bool success = SpiceStart(@"c:\sedatools");
  </code></pre>
  
  <p>The call to SpiceStart throws the exception "PInvokeStackImbalance", which "is likely because the managed PInvoke signature does not match the unmanaged target signature."</p>
  
  <p>Does anyone have any suggestions?  If I remove the char* and string from the parameters, then the method runs just fine.  However, I'd like to be able to pass the installation path of the application to the dll from C#.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Giawa</p>