tags:

views:

58

answers:

2

In some documentation, Ruby's Win32API has 'L' and 'N' to specify a "number"... and in some documentation, 'L' is "long". Is 'N' deprecated, and isn't 'L' the same as 'I' actually? A "number" is somewhat not so specific.

In http://rubyforge.org/docman/view.php/85/3463/API.html#M000001

There is no specifying a boolean parameter as 'B' or 'I', only the return value...

In http://www.ruby-doc.org/stdlib/libdoc/Win32API/rdoc/classes/Win32/Registry/Error.html#M001622

There is

 Win32API.new('kernel32.dll', 'FormatMessageA', 'LPLLPLP', 'L')

instead of the more common ['L', 'P', 'L', ...] format

hWnd is 'L' and therefore 'I' will work too? (hWnd is handle to window)

Boolean parameter is 'B' and is the same as 'I'?

So basically, we can use most things as 'I'? Even the 'P' should be a 4-byte, so 'I' should work as well? Is there a more formal specification?

Update: now that I think more about 'P', it actually will use a Ruby's String class object, and take the content buffer part and pass it into the C function. So using 'I' probably won't trigger this behavior. (example: such as using GetWindowText())

+1  A: 

L could be the same as I - but since I exists I would assume that it represents "short" (the C-Standard didn't specify the length of an "integer"). P could be the same as L - at least if you are using 32bit ruby.

Win32Api is really ugly and I would recommend against using it. You might take a look at FFI - Foreign Function Interface and the examples or Windows examples.

Marcel J.
The PickAx book for Ruby 1.9 also recommended using `DL` but i tried `gem install dl` and it doesn't exist.
動靜能量
`dl` should be included with ruby - try `require dl`. But the documentation for `dl` is even worse.
Marcel J.
+1  A: 

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.

Steven
I also saw in the README doc in the win32-api zip file about: `Removed the 'N' and 'n' prototypes. Always use 'L' for longs now.`
動靜能量