Module: Win::System::Info

Extended by:
Library
Defined in:
lib/win/system/info.rb

Overview

Contains constants and Win32 API functions related to system information functions. More functions of this type can be found here: msdn.microsoft.com/en-us/library/ms724953%28v=VS.85%29.aspx

Constant Summary collapse

ComputerNameNetBIOS =

Enum COMPUTER_NAME_FORMAT (for GetComputerNameEx). TODO: convert into FFI::Enum

0
ComputerNameDnsHostname =
1
ComputerNameDnsDomain =
2
ComputerNameDnsFullyQualified =
3
ComputerNamePhysicalNetBIOS =
4
ComputerNamePhysicalDnsHostname =
5
ComputerNamePhysicalDnsDomain =
6
ComputerNamePhysicalDnsFullyQualified =
7
ComputerNameMax =
8

Constants included from Library

Library::TYPES

Class Method Summary collapse

Methods included from Library

callback, define_api, define_snake_method, enforce_count, extended, function, generate_names, generate_signature, generate_snake_method_body, try_function

Class Method Details

.return_sized_string(encode = nil) ⇒ Object

Helper method that creates def_block returning (possibly encoded) string as a result of api function call or nil if api call was not successful. TODO: put this into some kind of helper?



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/win/system/info.rb', line 28

def return_sized_string( encode = nil )  #:nodoc:
  lambda do |api, *args|
    namespace.enforce_count( args, api.prototype, -2)
    buffer = FFI::MemoryPointer.new :char, 1024
    size = FFI::MemoryPointer.new(:long).write_long(buffer.size)
    args += [buffer, size]
    success = api.call(*args)
    return nil unless success
    num_chars = size.read_long
    if encode
      string = buffer.get_bytes(0, num_chars*2)
      string = string.force_encoding('utf-16LE').encode(encode)
    else
      string = buffer.get_bytes(0, num_chars)
    end
    string.rstrip
  end
end