title: Only one character returned from PyUnicode_AsWideCharString
body: <p>I'm trying to get in a Visual Studio 2012 C++ program the value of a string variable defined in a embedded Python environment using Python's C API.</p>
  
  <p>As embedded environment, I'm using Python 3.4.3 64-bit, which I downloaded from <a href="https://www.python.org/downloads/" rel="nofollow">https://www.python.org/downloads/</a></p>
  
  <p>This is the code I'm using in Visual Studio 2012 (target: Release, x64):</p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
  
    Py_Initialize();
  
    PyObject *main = PyImport_AddModule("__main__");
    PyObject *globals = PyModule_GetDict(main);
    PyRun_SimpleString("my_var = 'Hello, World!'; print('Value of my_var in Python: ' +  my_var)");
  
    PyObject* value = PyDict_GetItemString(globals, "my_var");
    wchar_t* fetched_value = PyUnicode_AsWideCharString(value, NULL);
    Py_DECREF(value);
  
    wchar_t result[20];
    wcscpy_s(result, 19, fetched_value);
    PyMem_Free(fetched_value);
  
    printf("Value of my_var in C: %s", result);
  
    Py_Finalize();
  
    return 0;
  }
  </code></pre>
  
  <p>When I run this code, I get this output:</p>
  
  <pre><code>Value of my_var in Python: Hello, World!
  Value of my_var in C: H
  </code></pre>
  
  <p>Why am I getting only the first character of <code>Hello, World!</code> in my call to <code>PyUnicode_AsWideCharString(value, NULL);</code>?</p>