Created
November 16, 2010 00:06
-
-
Save pkrumins/701215 to your computer and use it in GitHub Desktop.
GetUserName windows api call via haskell's FFI!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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