Berger, Daniel
2008-Apr-24 14:13 UTC
[Win32utils-devel] A generalized struct implementation for windows-api
Hi, After yet another win32-process bug, I''ve decided that we need some form of generalized struct handling for use with the windows-api library instead of packing and unpacking data structures manually. We currently do stuff like this: proc_info = 0.chr * 16 # sizeof(PROCESS_INFORMATION) Process.create(... proc_info ...) CloseHandle(proc_info[0,4]) I would like a way to generalize the creation of these structures. Something like this: require ''win32/struct'' Win32::Struct.new( ''PROCESS_INFORMATION'', :hProcess => HANDLE, :hThread => HANDLE, :dwProcessId => DWORD, :dwThreadId => DWORD ) And, with that in place, we could then write: proc_info = PROCESS_INFORMATION.new Process.create(... proc_info ...) CloseHandle(proc_info.hProcess) The struct would automatically handle the packing/unpacking behind the scenes based on the data type that was declared in the constructor. It''s easier to read and easier to maintain, IMO. And, we could predefine a bunch of the most common structures in advance so that users wouldn''t have to do this themselves. They would be immediately available. This could probably be an addon to the windows-api library already out there. What do you think? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.