Subject:
[ruby-ffi] Passing Windows VARIANT by value leads to segfault
From:
Stephan Schwab
Date:
1/18/11 12:23 PM
To:
ruby-ffi

Hi!

Given this code:

get_accState      = FFI::Function.new(:uint32, [:pointer,
Variant.by_value, :pointer], i_accessible_vtbl[:get_accState])
variant_out       = Variant.new

variant_in = Variant.new
variant_init(variant_in)
variant_in[:vt] = Constants::VT_I4   # 0x3
variant_in[:lVal] = 0  # CHILDID_SELF

acc_state_result  = get_accState.call(i_accessible, variant_in,
variant_out)
fail "Can't query for button state. HRESULT = 0x" +
acc_state_result.to_s(16) unless acc_state_result == Constants::S_OK
# S_OK = 0

I get a segmentation fault when calling get_accState.call()

The method get_accState() allows me to skip the second parameter and
pass in NULL instead. If I do that (after changing the parameter type
to a pointer and using 'nil') the function returns S_OK and does not
crash.

What might be the reason for the segmentation fault given this code?

Stephan