title: using C# DLL from C++: problem with functions with strings as parameters
body: <p>Starting from this example: <a href="http://support.microsoft.com/kb/828736" rel="nofollow noreferrer">http://support.microsoft.com/kb/828736</a> I have tried to add a test function in my C# DLL which takes strings as parameters.  My C# DLL code is as follows:</p>
  
  <pre><code>namespace CSharpEmailSender
  {
     // Interface declaration.
     public interface ICalculator
     {
         int Add(int Number1, int Number2);
         int StringTest(string test1, string test2);
     };
  
  // Interface implementation.
  public class ManagedClass : ICalculator
  {
      public int Add(int Number1, int Number2)
      {
          return Number1 + Number2;
      }
  
      public int StringTest(string test1, string test2)
      {
          if (test1 == "hello")
              return(1);
  
          if (test2 == "world")
              return(2);
  
          return(3);
      }
  }
  </code></pre>
  
  <p>I then register this DLL using regasm.  I use it in my C++ app like so:</p>
  
  <pre><code>using namespace CSharpEmailSender;
  using namespace std;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
  // Initialize COM.
  HRESULT hr = CoInitialize(NULL);
  
  // Create the interface pointer.
  ICalculatorPtr pICalc(__uuidof(ManagedClass));
  
  long lResult = 0;
  long lResult2 = 0;
  
  pICalc-&gt;Add(115, 110, &amp;lResult);
  wprintf(L"The result is %d", lResult);
  
  pICalc-&gt;StringTest(L"hello", L"world", &amp;lResult2);
  wprintf(L"The result is %d", lResult2);
  
  // Uninitialize COM.
  CoUninitialize();
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>After running this, lResult is correct (with value of 225), but lResult2 is zero.  Any idea what I'm doing wrong?</p>