Subject:
[ruby-ffi] Test pointer results
From:
Brett Blackham
Date:
9/8/09 8:13 AM
To:
ruby-ffi


I have the following code:

  DWORD     = FFI::Type::UINT32
  ...
  ffi_lib 'kernel32'
  attach_function :CreateToolhelp32Snapshot, [DWORD, DWORD], :pointer


  snapshot = KERNEL32.CreateToolhelp32Snapshot
( Win32DebuggerDefines::TH32CS_SNAPTHREAD, @pid
  if snapshot == nil
    return false
  end


  However, this code fails at "if snapshot == nil". It appears that
CreateToolhelp32Snapshot will always return a pointer. Even if @pid is
not a valid process ID. Additionally, FFI pointers don't like to be
compared to nil. Any thoughts on how I could test the results to
ensure the CreateToolhelp32Snapshot call worked?

Thanks