Ruby win32 api interface

后端 未结 3 1496
囚心锁ツ
囚心锁ツ 2020-12-06 03:12

I need to access a few functions of the win32 library in ruby. I have found extremely sparse information on the Win32API class online, so I\'m asking here.

I know th

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 03:46

    I think you'll have to investigate the String#pack method to get your APPBARDATA struct filled correctly.

    See the "Pickaxe" book section on Win32 and Ruby (scroll down to the Win32API class definition).

    So as already spotted, you'll use a 'P' argument and you'll pass a properly-packed String (or Strings) into the function.

    Alternatively, if you have a little time to investigate, you may want to look at the FFI library, which seems to do everything in a rather more friendly way. I have no direct experience, but try looking at

    • The original announcement by Charles Nutter of the JRuby team, where there's an example of a much nicer way to declare C structs.
    • The Ruby FFI home page at Sun

提交回复
热议问题