From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d50803f457a25d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: GtkAda Problem Date: Tue, 20 Jul 2004 19:14:59 +0100 Message-ID: References: <1udKc.98748$dP1.333832@newsc.telia.net> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de s9GV/uTO1CuWmME7VaQaMArSZTxfGg4qvbu7mvlC48uq5RFnQ= User-Agent: Opera M2/7.51 (Win32, build 3798) Xref: g2news1.google.com comp.lang.ada:2285 Date: 2004-07-20T19:14:59+01:00 List-Id: On Mon, 19 Jul 2004 15:55:31 -0400, Warren W. Gay VE3WWG wrote: > ... > There is a problem with this: routines in the generic > instantiation do not permit 'Access. I tried this once, and > was burned (ouch). I forget what the rationale behind it was, > but I found it extremely inconvenient! :< I think the rationale was that a generic unit can be instantiated at any level, but it was not desired to require, in effect, checks inside the body of an instantiation. I've always been in favour of dropping the restrictions on levels (which would require implementations to put in dynamic checks in various places). Anyway, as per Randy's reply, Ada 2005 has already got a solution to the problem (anonymous access-to-subprogram parameters). > A specific code sample would help in this discussion, but I > don't have one at the moment. Here's some code copied straight out of a test program I wrote, to try out some interfacing of GNAT to Win32: ~~~ function Main_Window_Control ( Window: in Win32.WinDef.HWND; Message: in Win32.UINT; Param_1: in Win32.WPARAM; Param_2: in Win32.LPARAM) return Win32.LRESULT; pragma Convention(StdCall,Main_Window_Control); function Main_Window_Control ( Window: in Win32.WinDef.HWND; Message: in Win32.UINT; Param_1: in Win32.WPARAM; Param_2: in Win32.LPARAM) return Win32.LRESULT is begin case Message is when Win32.WinUser.WM_CREATE => Create_Main_Window(Window); when Win32.WinUser.WM_PAINT => Paint_Main_Window(Window); when Win32.WinUser.WM_DESTROY => Win32.WinUser.PostQuitMessage(0); when Win32.WinUser.WM_SIZE => Resize_Main_Window( Window, Width => LOWORD(Win32.ULONG(Param_2)), Height => HIWORD(Win32.ULONG(Param_2)) ); when Win32.WinUser.WM_VSCROLL => Scroll_Main_Window( Window, Way => Down, Action => LOWORD(Win32.ULONG(Param_1)), Value => HIWORD(Win32.ULONG(Param_1)) ); when Win32.WinUser.WM_HSCROLL => Scroll_Main_Window( Window, Way => Across, Action => LOWORD(Win32.ULONG(Param_1)), Value => HIWORD(Win32.ULONG(Param_1)) ); when others => return Win32.WinUser.DefWindowProc(Window,Message,Param_1,Param_2); end case; return 0; -- indicates no error end Main_Window_Control; ------------------------------------------------------------------------ Main_Window_Class_Descriptor: aliased Win32.WinUser.WNDCLASS := ( style => Win32.WinUser.CS_HREDRAW or Win32.WinUser.CS_VREDRAW, lpfnWndProc => Main_Window_Control'Access, hInstance => Win32.WinMain.Get_hInstance, hIcon => Win32.WinUser.LoadIcon( C_NULL, Win32.LPCSTR(Win32.WinUser.IDI_APPLICATION) ), hCursor => Win32.WinUser.LoadCursor( C_NULL, Win32.LPCSTR(Win32.WinUser.IDC_ARROW) ), hbrBackground => Win32.WinDef.HBRUSH( Win32.WinGDI.GetStockObject(Win32.WinGDI.WHITE_BRUSH) ), lpszMenuName => null, lpszClassName => Win32.Addr( Win32.CHAR_array'("SysMets3") & Win32.NUL ), cbClsExtra | cbWndExtra => 0 ); Main_Window_Class: Win32.WinDef.ATOM; procedure Register_Main_Window_Class is begin Main_Window_Class := Win32.WinUser.RegisterClass(Main_Window_Class_Descriptor'Access); if Main_Window_Class = 0 then raise Win32_Error; end if; end Register_Main_Window_Class; ~~~ The trick is that this is all defined in a library-level package, so I can use Main_Window_Control'Access with impunity. If you're wondering, the program is an Adafication of the 'SYSMETS3' program of Charles Petzold's classic Programming Windows 95 book. (And it works perfectly.) You can see how this kind of program can get gummed up by the glue (which is why I tried to move most of the glue code into a separate package). -- Nick Roberts