title: Convert managed String (C#) to LPCOLESTR (C++)
body: <p>I wave a method in C++ that receives a parameter of the LPCOLESTR type. I'm accessing this method through C#, but I can't make the correct conversion between String and this type.</p>
  
  <p>Let's say the method signinature in C++ is:</p>
  
  <pre><code>void Something(LPCOLESTR str)
  </code></pre>
  
  <p>In C#, I'm trying to call it (all reference issues to access the method through a DLL have been solved already):</p>
  
  <pre><code>String test = "Hello world";
  Something(test);
  </code></pre>
  
  <p>But with no luck, of course. If anyone can help me, I'd be very glad. Thank you!</p>
  
  <hr>
  
  <p>Code snippet:</p>
  
  <p>As an example, here's my C++ portion of code, defined in the file MixedCodeCpp.h (CLR Class Library)</p>
  
  <pre><code>#include "windows.h"  
  #pragma once  
  using namespace System;
  
  namespace MixedCodeCpp
  {
      public ref class MyClass
      {
      public:
          HRESULT Something(LPCOLESTR str)
          {
              return S_OK;
          }
      };
  }
  </code></pre>
  
  <p>And here's my code in C# (I've added a reference to the C++ project in the C# project, through Visual Studio):</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();  
  sb.Append("Hello world");  
  MixedCodeCpp.MyClass cls = new MixedCodeCpp.MyClass();  
  cls.Something(sb);
  </code></pre>