From: Michael Davis Date: 2003-07-28T14:03:46+09:00 Subject: Calling Win32API on XP with cygwin is failing Hello again, Has anyone experienced any issues with accessing Win32API using cygwin on XP. Simple calls to Win32API functions are all failing. I am running the latest cygwin on XP. The gcc compiler is gcc version 3.3, and Ruby 1.6.8 (compiled from source). On another similar note, Ruby 1.6.5 and 1.6.7 fail to compile with the following compile errors: gcc -I. -g -O2 -I. -I. -I/usr/local/include -c ./missing/strftime.c missing/strftime.c: In function `strftime': missing/strftime.c:450: error: too many arguments to function `timezone' make: *** [strftime.o] Error 1 Ruby 1.6.8 compiled after I removed several extensions such as gdb because they were failing to compile. Win32API compilied successfully. Here is the Ruby snippet I am trying to run (CreateWindow fails on XP, works on 2000, it should create a little see through window for 6 seconds): require 'Win32API' # this uses the Win32API for calling functions in windows DLLs. CreateWindow = Win32API.new('user32', 'CreateWindowEx', ['L', 'p', 'p', 'l', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'p'], 'L') DestroyWindow = Win32API.new('user32', 'DestroyWindow', ['L'], 'L') PostQuitMessage = Win32API.new('user32', 'PostQuitMessage', ['L'], 'L') ShowWindow = Win32API.new('user32', 'ShowWindow', ['L', 'L'], 'L') Sleep = Win32API.new('kernel32', 'Sleep', ['L'], 'L') GetError = Win32API.new('kernel32','GetLastError', [], 'L') WM_CLOSE = 0x0010 WM_PAINT = 0x000F # Window Styles WS_OVERLAPPED = 0x00000000 WS_POPUP = 0x80000000 WS_CHILD = 0x40000000 WS_MINIMIZE = 0x20000000 WS_VISIBLE = 0x10000000 WS_DISABLED = 0x08000000 WS_CLIPSIBLINGS = 0x04000000 WS_CLIPCHILDREN = 0x02000000 WS_MAXIMIZE = 0x01000000 WS_CAPTION = 0x00C00000 # /* WS_BORDER | WS_DLGFRAME */ WS_GROUP = 0x00020000 WS_SYSMENU = 0x00080000 WS_THICKFRAME = 0x00040000 WS_MINIMIZEBOX = 0x00020000 WS_MAXIMIZEBOX = 0x00010000 WS_BORDER = 0x00800000 WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU) WS_CHILDWINDOW = (WS_CHILD) # Extended Window Styles WS_EX_TOPMOST = 0x00000008 WS_EX_TRANSPARENT = 0x00000020 WS_EX_TOOLWINDOW = 0x00000080 WS_EX_WINDOWEDGE = 0x00000100 WS_EX_CLIENTEDGE = 0x00000200 WS_EX_OVERLAPPEDWINDOW =(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) def create_window(title, x, y, w, h) window_id = 0 if (title) type = WS_EX_OVERLAPPEDWINDOW attr = (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZE) window_id = CreateWindow.call(type, 'static', title.to_s, attr, x, y, w, h, 0, 0, 0, 0) end raise "create_window(#{title.inspect}, #{x}, #{y}, #{w}, #{h}) - failed: #{GetError.call()}" if (!window_id || window_id == 0) #hide_window(window_id) #SetWindowLong.call(window_id, GWL_USERDATA, ('Win32API_MessageHandler_window'.intern.to_i)) return window_id end window_id = create_window('Test', 20, 20, 400, 200) ShowWindow.call(window_id, 1) #SW_NORMAL = 1, SW_SHOW = 5 Sleep.call(6000) SendMessage.Call(window_id, WM_CLOSE, 0, 0)