title: Import GetStdHandle function from kernel32.dll in assembly
body: <p>I have proble with import GetStdHandle function from kernel32.dll, when i try to link my app i receive that error:</p>
  
  <pre><code>winapiwrite.obj:winapiwrite.asm:(.text+0x7): undefined reference to `GetStdHandle@4'
  </code></pre>
  
  <p>my app code:</p>
  
  <pre><code>;winapiwrite.asm
  ;
  ;Command line
  ;nasm -f win32 winapiwrite.asm
  ;ld winapiwrite.obj -o winapiwrite.exe c:\windows\system32\kernel32.dll
  
  [bits 32]
  extern _ExitProcess@4
  extern _GetStdHandle@4
  extern _WriteConsoleA@20
  global _WinMain@16
  
  section .data
  str_hello:
    db "Hello world!", 0  ;length = 12bytes
  
  section .text
  _WinMain@16:
    ;stack frame
    push ebp
    sub esp, 4
  
    ;GetStdHandle( -11 ): stdoutput
    push -11
    call _GetStdHandle@4
    mov ebx, eax
  
    ;WriteConsoleA( Output, &amp;text, len, &amp;bytes, reserved ) 
    push 0
    lea eax, [ebp-4]
    push eax
    push 12
    push str_hello
    push ebx
    call _WriteConsoleA@20
  
    ;ExitProcess( 0 )
    push 0
    call _ExitProcess@4
  ;END OF _WinMain@16
  </code></pre>
  
  <p>additional when i change name of function in code from:</p>
  
  <pre><code>_GetStdHandle@4
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>_GetStdHandle
  </code></pre>
  
  <p>i receive that error:</p>
  
  <pre><code>ertr000006.o:(.rdata+0x0): undefined reference to `_pei386_runtime_relocator'
  </code></pre>
  
  <p>I'm don't know what ExitProcess and WriteConsoleA import with no problem and with GetStdHandle are problems, I'm thinking about that from hours and I haven't any solution.</p>
  
  <p>Thanks for any help.</p>