Skip to content

Instantly share code, notes, and snippets.

@pkrumins
Created November 16, 2010 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkrumins/701215 to your computer and use it in GitHub Desktop.
Save pkrumins/701215 to your computer and use it in GitHub Desktop.
GetUserName windows api call via haskell's FFI!
{-# LANGUAGE ForeignFunctionInterface #-}
import System.Win32.Types
import Foreign
import Foreign.C
foreign import stdcall unsafe "windows.h GetUserNameW"
c_GetUserName :: LPTSTR -> LPDWORD -> IO Bool
getUserName :: IO String
getUserName =
allocaArray 512 $ \ c_str -> do
with 512 $ \ c_len -> do
failIfFalse_ "GetUserName" $ c_GetUserName c_str c_len
peekTString c_str
-- ghci -ladvapi32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment