From: Jan Svitok Date: 2006-10-11T16:47:27+09:00 Subject: Re: How to call WinAPI in ruby where the parameter I Pass is both Input and Output On 10/11/06, Madhusudan Narayan wrote: > Hi all, > I am trying to determine windows OS version through Ruby using Win32API > > There is a Win32 API GetVersionEx() > *BOOL GetVersionEx( > LPOSVERSIONINFO lpVersionInfo > );* > in Kernel32.dll > typedef struct _OSVERSIONINFO { > DWORD dwOSVersionInfoSize ; > DWORD dwMajorVersion ; > DWORD dwMinorVersion ; > DWORD dwBuildNumber ; > DWORD dwPlatformId ; > TCHAR szCSDVersion [128]; > } OSVERSIONINFO; > I was not able to get the result using api=Win32API.new > ("Kernel32","GetVersionEx",['P'],['P']) > > the parameter lpVersionInfo is both input and output I don't know if I'm > using Win32API.new() properly Hi, > BOOL GetVersionEx( > LPOSVERSIONINFO lpVersionInfo > ); use api=Win32API.new("Kernel32","GetVersionEx",['P'],['L']) (the first array are parameters that you send to function (LPOSVERSIONINFO), no matter if they are read or write or both, the second is the return value of the function (BOOL)) Then allocate large enough string, fill in the required fields, and pass it as a parameter (Array.pack is useful for this). For more inspiration see win32utils project, especially windows-pr gem. I've looked briefly whether Dan haven't wrapped this function already, but I haven't found. When you succeed, maybe you can propose a patch to him.