Skip to content

Instantly share code, notes, and snippets.

@RX14

RX14/win.cr Secret

Last active May 31, 2017 18:20
Show Gist options
  • Save RX14/2bf5cbca185e3b449576523e2e7e188c to your computer and use it in GitHub Desktop.
Save RX14/2bf5cbca185e3b449576523e2e7e188c to your computer and use it in GitHub Desktop.
lib LibWindows
STD_INPUT_HANDLE = 0xFFFFFFF6_u32
STD_OUTPUT_HANDLE = 0xFFFFFFF5_u32
STD_ERROR_HANDLE = 0xFFFFFFF4_u32
alias DWord = UInt32
alias Handle = Void*
alias SizeT = UInt64 # FIXME
struct Overlapped
internal : SizeT*
internal_high : SizeT*
pointer : Void*
event : Handle
end
fun get_std_handle = GetStdHandle(std_handle : DWord) : Handle
fun get_file_type = GetFileType(file : Handle) : DWord
fun write_file = WriteFile(file : Handle, buffer : UInt8*, size : DWord, written : DWord*, overlapped : Overlapped*) : Bool
fun close_handle = CloseHandle(file : Handle) : Bool
end
handle = LibWindows.get_std_handle(LibWindows::STD_OUTPUT_HANDLE)
str = "Hello World!\n"
written = 0_u32
LibWindows.write_file(handle, pointerof(str.@c), str.@bytesize, pointerof(written), nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment