How to call external libs on windows preview?

Hi,

Could someone point me to some example of using lib under windows?

Is that possible yet to call external functions from libraries?
Specifically I wanted to see if I can access the win32 API for the clipboard, not sure if that matters.

Yeah sure, loading shared libraries works well on Windows. Otherwise the standard library and runtime wouldn’t even be able to function.

Defining lib bindings is really not different from other platforms.

You can take a look at the bindings for windows in stdlib for inspiration: crystal/src/lib_c/x86_64-windows-msvc/c at master · crystal-lang/crystal · GitHub

1 Like

Thanks! Example for reference:

@[Link("User32")]
lib User32
  alias DWORD = UInt32
  fun  GetClipboardSequenceNumber() : DWORD
end

puts User32.GetClipboardSequenceNumber().inspect

edit: Added the alias that was pulled in invisibly from using LibC as a name. Just to avoid confusion if anyone ever finds this.

1 Like