Subject: [ruby-ffi] Re: Test pointer results |
From: Wayne Meissner |
Date: 9/8/09 2:39 PM |
To: ruby-ffi@googlegroups.com |
You can call Pointer#null? to check if it is null e.g. if snapshot.null? return false end 2009/9/8 Brett Blackham <brett.blackham@gmail.com>:
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