title: Creating C# to C++ bridge: Why do I get a AccessViolationException when calling DLL?
body: <p>I'm exploring the idea of building a bridge between a DLL plugin for a 3rd party app and a C# app.  I'm writing both the plugin DLL and the C# application.  The plugin will be loaded into the 3rd party app and then I want to use call the plugin from C# to indirectly get data from the 3rd party app.</p>
  
  <p>I am able to successfully call an exported function from the DLL from C#. For example:</p>
  
  <p>C++ DLL:</p>
  
  <pre><code>extern "C" __declspec(dllexport) char * HelloFromDll()
  {
      char *result;
      result = "Hello from my DLL";
      return result;
  }
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>using System.Runtime.InteropServices;
  
  [DllImport(@"MyDll.dll")]
  private static extern string HelloFromDll();
  </code></pre>
  
  <p>I can then call this DLL function from C# and display the string in the UI.  However, as soon as I create an export function that calls a function from my 3rd party app, I get an AccessViolationException.  For example,</p>
  
  <pre><code>extern "C" __declspec(dllexport) char * GetData()
  {
      char *result;
      result = 3rdPartyLibrary::SomeFunction();
      return result;
  }
  </code></pre>
  
  <p>Through some testing, the error seems to occur as soon as I make a call to a 3rd party function.  How can I fix this?</p>