title: Console output with WinAPI WriteConsole
body: <p>I'm trying to do hello world with winapi functions. It's kind of working but I would love to have it done the proper way.</p>
  
  <p>So i got code like this:</p>
  
  <pre><code>int main(){
      HANDLE std_out;
      int i;
      char *error_msg;
  
      std_out = GetStdHandle(STD_OUTPUT_HANDLE);
  
      if(std_out == INVALID_HANDLE_VALUE){
          MessageBox(NULL,"stdout not available","Error",MB_OK);
          return 1;
      }
  
      AttachConsole(ATTACH_PARENT_PROCESS);
  
      if(!WriteConsoleA(std_out,"hhh\n",4,&amp;i,NULL)){
          FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,NULL,GetLastError(),0,&amp;error_msg,4,NULL);
          MessageBox(NULL,error_msg,"Error",MB_OK);
      }
  
      return 42;
  }
  </code></pre>
  
  <p>Also I'm a little bit experimenting so I link with /entry:main /subsystem:windows</p>
  
  <p>the output is then like:</p>
  
  <pre><code>%PATH_TO_WORKING_DIR%&gt;hhh(CRLF)
  </code></pre>
  
  <p>then it waits until I press RETURN and then the program terminates, which as you probably agree is very crapy "hello world". Any ideas how to get rid of that PWD and necessity to press return are very welcomed, thx for reading.</p>