title: WriteConsoleOutputCharacter Access violation
body: <p>I've been trying to execute a command on cmd and i'm using WriteConsoleOutputCharacter. My code is the following:</p>
  
  <pre><code>int main( void )
  {
      HANDLE hStdout;
      hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  
      fun(hStdout,L"file1",L"file2");
      return 0;
  }
  
  void fun( HANDLE hConsole,wchar_t* str1,wchar_t* str2 )
  {
     COORD coordScreen = { 0, 0 };    // home for the cursor 
     LPDWORD cCharsWritten=0;
     //LPDWORD cCharsWritten; that was originally
     CONSOLE_SCREEN_BUFFER_INFO csbi; 
     DWORD dwConSize;
  
     if( !GetConsoleScreenBufferInfo( hConsole, &amp;csbi ))
     {
        return;
     }
  
     dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  
     std::wstring ss;
     ss=std::wstring(L"cp ")+ str1+std::wstring(L" ")+str2;
  
  
     if( !WriteConsoleOutputCharacter( hConsole,        // Handle to console screen buffer 
                                  ss.c_str(),     // Character to write to the buffer
                                  dwConSize,       // Number of cells to write 
                                  coordScreen,     // Coordinates of first cell 
                                  cCharsWritten ))// Receive number of characters written
     {
        return;
     }
  
  
  
     if( !GetConsoleScreenBufferInfo( hConsole, &amp;csbi ))
     {
        return;
     }
  
  
     if( !FillConsoleOutputAttribute( hConsole,         // Handle to console screen buffer 
                                  csbi.wAttributes, // Character attributes to use
                                  dwConSize,        // Number of cells to set attribute 
                                  coordScreen,      // Coordinates of first cell 
                                  cCharsWritten )) // Receive number of characters written
     {
        return;
     }
  
     SetConsoleCursorPosition( hConsole, coordScreen );
  }
  </code></pre>
  
  <p>The code compiles fine but t first i was getting an error saying that i was using cCharsWritten without initializing it.So i set it to 0 (LPDWORD cCharsWritten=0;).But then i keep getting </p>
  
  <pre><code>Unhandled exception at 0x772c5033 in CpProgrammatically.exe: 0xC0000005: Access violation reading location 0x00446000.
  </code></pre>
  
  <p>at the line that has the call of WriteConsoleOutputCharacter.
  I've tried pretty much anything i could imagine but i can't figure it out.Is there something wrong on the way i use the cCharsWritten variable?Is there a problem with thefact that ss is unicode string?Any help would be much appreciated.</p>