Ruby Win32 API Interface

In Ruby's Win32API.new, isn't 'L' the same as 'I', and what about 'N' or 'P'?

I'm looking at the win32-api source code, and it looks like the only difference between 'L' and 'I' is that 'L' calls rb_num2ulong and 'I' calls rb_num2int in <ruby.h>. So I guess the only difference is treatment as a signed value or not. 'P' also results rb_num2ulong, but it follows additional logic so I would probably stick to what the documentation suggests. I coudln't find any mention of 'N' in the latest version of win32-api (1.4.5), so it's probably deprecated. The Windows APIs do not return boolean, but some return BOOL which is (surprise! ) an int. In short, I don't think you should use 'I' for everything. The win32-api documentation is pretty scant from what I've seen. At least the source code is available for browsing.

How do I call Windows DLL functions from Ruby?

Have a look at Win32API stdlib. It's a fairly easy (but arcane) interface to the Windows 32 API, or DLLs.

Documentation is here, some examples here. To give you a taste:

require "Win32API"    
def get_computer_name
name = " " * 128
size = "128"
Win32API.new('kernel32', 'GetComputerName', ['P', 'P'], 'I').call(name, size)
name.unpack("A*")
end

Can I call REST web services from Windows Mobile app

Yes you can. I've done it lots using the Win32 wininet API.

You can also do it in C# using the System.Net HttpWebRequest API.



Related Topics



Leave a reply



Submit