comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: GtkAda Problem
Date: Tue, 20 Jul 2004 19:14:59 +0100
Date: 2004-07-20T19:14:59+01:00	[thread overview]
Message-ID: <opsbf7m9b0p4pfvb@bram-2> (raw)
In-Reply-To: RGVKc.11686$Gf7.343217@news20.bellglobal.com

On Mon, 19 Jul 2004 15:55:31 -0400, Warren W. Gay VE3WWG  
<ve3wwg@cogeco.ca> 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



  parent reply	other threads:[~2004-07-20 18:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-17 16:05 GtkAda Problem Oliver Doerler
2004-07-17 16:11 ` Sorry wrong Def.! Oliver Doerler
2004-07-17 17:38 ` GtkAda Problem Björn Persson
2004-07-17 20:00   ` Nick Roberts
2004-07-17 22:40     ` Jeffrey Carter
2004-07-18  0:01       ` Nick Roberts
2004-07-18 11:29         ` Simon Wright
2004-07-18 14:17           ` Nick Roberts
2004-07-19 19:55             ` Warren W. Gay VE3WWG
2004-07-19 21:58               ` Ludovic Brenta
2004-07-19 22:59                 ` Ed Falis
2004-07-20 16:58                 ` Warren W. Gay VE3WWG
2004-07-20 18:14               ` Nick Roberts [this message]
2004-07-19 23:55         ` Randy Brukardt
2004-07-17 17:44 ` Nick Roberts
2004-07-21 20:15 ` Oliver Doerler
  -- strict thread matches above, loose matches on Subject: below --
2003-01-07 11:45 gtkada problem Evangelista Sami
2003-01-07 18:46 ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox