title: Cannot marshal 'return value': Invalid managed/unmanaged type combination
body: <p>I have this function in an unmanaged library and I want to call it in C#:</p>
  
  <p><code>unsigned char __stdcall InitDev(unsigned char comport, long BaudRate)</code></p>
  
  <p>and this is in C#</p>
  
  <pre><code>[System.Security.SuppressUnmanagedCodeSecurity]
  [DllImport("*.dll", CallingConvention = CallingConvention.Cdecl,CharSet =CharSet.Auto)]
  public static extern byte[] InitDev(byte[] comport, [Out]long BaudRate);
  </code></pre>
  
  <p>but when I call this function in C# I get the following error</p>
  
  <blockquote>
    <p>"Cannot marshal 'return value': Invalid managed/unmanaged type combination."</p>
  </blockquote>
  
  <pre><code>string COM = "COM3";
  byte[] ptr = new byte[1];
  try
  {
      ptr = InitDev(Encoding.ASCII.GetBytes(COM), 9600);
  }
  catch (Exception ex)
  {
      MessageBox.Show(ex.Message);
  }
  </code></pre>
  
  <p>I am new to this if a little guidance is provided I will be able to resolve this issue</p>
  
  <p><a href="https://i.stack.imgur.com/mbXvM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mbXvM.png" alt="enter image description here"></a></p>