title: How can I use a C++ function that returns a char based on user input (cin), from a .dll in unity?
body: <p>I've written a C++ dll and imported it to unity. The dll contains one function which returns a char that gets it's value from cin. This is the .cpp file:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &quot;InputTest2.h&quot;
  
  using namespace std;
  
  extern &quot;C&quot; {
      
      char DLL_EXPORT getInput()
      {
          char input;
          cin &gt;&gt; input;
          //cout &lt;&lt; input; //for internal testing in main
          return input;
      }
  }
  </code></pre>
  <p>This is the header file:</p>
  <pre><code>#pragma once
  
  #define DLL_EXPORT __declspec(dllexport)
  
  extern &quot;C&quot; {
  
      char DLL_EXPORT getInput();
  
  }
  </code></pre>
  <p>When testing the function in main, it works as expected: the console prints the key I've pressed on and terminates. However, when using the function in Unity, all I get is one blank message in the console when hitting play, and then a '?' character printed every update, no matter what key I'm pressing. Function is called from update.
  Here is the C# code:</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.Runtime.InteropServices;
  using UnityEngine;
  
  public class CPPbackend : MonoBehaviour
  {
      [DllImport(&quot;InputTest2&quot;)]
      private static extern char getInput();
  
      void Update()
      {
          //if (Input.anyKeyDown)
          //{
              print(getInput());
          //}
          
      }
  }
  </code></pre>
  <p>If I un-comment the if statement, I get a '?' printed whenever I press a key. I have also tried writing getInput().ToString() thinking maybe the char type is the problem, but that didn't change anything. I've also tried deleting the &quot;using namsepace std;&quot; line and instead writing std::cin within the function, but that didn't change anything either.
  There are no errors with importing/using the dll in unity, i've also written some functions that receive parameters and return data types in a dll and imported it to unity, and it worked fine.
  I've recently started learning C++, and this is just an exercise, but I'd very much like to know what am I doing wrong.
  Thanks!</p>