【发布时间】:2014-05-12 08:49:24
【问题描述】:
我正在尝试在我的 ruby 程序中使用 EnumProcesses:
BOOL WINAPI EnumProcesses(
_Out_ DWORD *pProcessIds,
_In_ DWORD cb,
_Out_ DWORD *pBytesReturned
);
我需要定义一个指向无符号整数数组的指针,我这样做的方式如下:
require 'ffi'
module Win32
extend FFI::Library
ffi_lib 'Psapi'
ffi_convention :stdcall
attach_function :EnumProcesses, [:pointer, :uint, :pointer], :int
end
process_ids = FFI::MemoryPointer.new(:uint, 1024)
bytes_returned = FFI::MemoryPointer.new(:uint)
if Win32.EnumProcesses(process_ids, process_ids.size, bytes_returned) != 0
puts bytes_returned.read_string
end
上面返回的字节的输出是一种像x☺这样的垃圾字符
让我知道我哪里做错了?
【问题讨论】: