comp.lang.ada
 help / color / mirror / Atom feed
* Windows Programming With ActiveAda for Win32s
@ 1995-03-21 18:32 Charlie Lenahan
  1995-03-22 14:59 ` jjj@sage.inel.gov
  1995-03-24 12:39 ` Mitch Gart
  0 siblings, 2 replies; 5+ messages in thread
From: Charlie Lenahan @ 1995-03-21 18:32 UTC (permalink / raw)


We are trying to Use ActiveAda for Windows 5.1.3 to Create a Dialog Box. 
Regular Windows Programming you must use a call to MakeProcINstance before you
call CreateDialog(). How do you Get around this by using the address of the 
callback function for that dialog box.

Inst:Handle:=GetModuleHandle(C_NULL);

DlgHnd:Hwnd;

Dlgproc:lpvoid:=package.dlg_proc'address;

prt : hwnd;

begin

prt := CreateWindowEx();

dlghnd := CreateDialog(inst, CString("dialog_name"), prt, Convert(DlgProc));

...

end;

.rc file ...
DIALOG dialog_name ...

This is the general concept we have been attempting.  The dlghnd is not created
and a call to GetLastError returns 87 - Invalid Parameter.  What are we doing wrong???




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Windows Programming With ActiveAda for Win32s
  1995-03-21 18:32 Charlie Lenahan
@ 1995-03-22 14:59 ` jjj@sage.inel.gov
  1995-03-24 12:39 ` Mitch Gart
  1 sibling, 0 replies; 5+ messages in thread
From: jjj@sage.inel.gov @ 1995-03-22 14:59 UTC (permalink / raw)


charliel@ansel.intersource.com (Charlie Lenahan) wrote:
>
> We are trying to Use ActiveAda for Windows 5.1.3 to Create a Dialog Box.
> Regular Windows Programming you must use a call to MakeProcINstance before you
> call CreateDialog(). How do you Get around this by using the address of the
> callback function for that dialog box.
>
Here's what I do for a simple 'About' Dialog:

  -- About WinProc specification

  -- Note the following is in a package spec.

  function DIALOG_ABOUT_WINPROC (Window  : HWND;
                             Message : UINT;
                             WPara   : WPARAM;
                             LPara   : LPARAM) return LRESULT;

  pragma CALL_IN (WIN32, DIALOG_ABOUT_WINPROC);

  -- note the following is in a package body


  -- About Winproc Event Handler

  function DIALOG_ABOUT_WINPROC_A (hDlg    : HWND;
                               Message : UINT;
                               WPara   : WPARAM;
                               LPara   : LPARAM) return LRESULT is
      B : BOOL;

  begin
    case (Message) is
      when WM_INITDIALOG =>
        return 1;

      when WM_COMMAND =>
        case (WPara) is
          when IDOK  =>
            B := EndDialog (hDlg, 0);
            return 1;
          when others =>
            return 0;
        end case;

      when others =>
        return 0;
    end case;

    return 0;
  end DIALOG_ABOUT_WINPROC_A;


  function DIALOG_ABOUT_WINPROC (Window  : HWND;
                             Message : UINT;
                             WPara   : WPARAM;
                             LPara   : LPARAM) return LRESULT is

    RESULT : LRESULT;

  begin
    ENTER_CALLBACK;
    RESULT := DIALOG_ABOUT_WINPROC_A (Window, Message, WPara, LPara);
    EXIT_CALLBACK;
    return RESULT;

  end DIALOG_ABOUT_WINPROC;


-- Here's the main program

 Inst        : HANDLE  := GetModuleHandle (C_NULL);
 window      : HWND;
 AboutDlg    : constant STRING := "#200" & ASCII.NUL;

-- Note I am using a numeric identifier for the DialogBox but you
-- can just as easily use a string.

-- A standard Overloaded Convert Function for Ada-Windows Types
  function CONVERT is new UNCHECKED_CONVERSION (INTEGER, LPVOID);
  function CONVERT is new UNCHECKED_CONVERSION (LPVOID,  INTEGER);



  Error := DialogBox (Inst,AboutDlg'Address,Window,
                      CONVERT(DIALOG_ABOUT_WINPROC'ADDRESS));



-- I coded this using the Alsys NT ActivAda Compiler but it should
-- be pretty close to ActivAda 5.1.3

Jon Jensen
AdaSAGE Development Team
Idaho National Engineering Lab




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Windows Programming With ActiveAda for Win32s
  1995-03-21 18:32 Charlie Lenahan
  1995-03-22 14:59 ` jjj@sage.inel.gov
@ 1995-03-24 12:39 ` Mitch Gart
  1 sibling, 0 replies; 5+ messages in thread
From: Mitch Gart @ 1995-03-24 12:39 UTC (permalink / raw)


Charlie Lenahan (charliel@ansel.intersource.com) wrote:
: We are trying to Use ActiveAda for Windows 5.1.3 to Create a Dialog Box. 
: Regular Windows Programming you must use a call to MakeProcINstance before you
: call CreateDialog(). How do you Get around this by using the address of the 
: callback function for that dialog box.

: Inst:Handle:=GetModuleHandle(C_NULL);

: DlgHnd:Hwnd;

: Dlgproc:lpvoid:=package.dlg_proc'address;

: prt : hwnd;

: begin

: prt := CreateWindowEx();

: dlghnd := CreateDialog(inst, CString("dialog_name"), prt, Convert(DlgProc));

: ...

: end;

: .rc file ...
: DIALOG dialog_name ...

: This is the general concept we have been attempting.  The dlghnd is not created
: and a call to GetLastError returns 87 - Invalid Parameter.  What are we doing wrong???


MakeProcInstance is an odd beast.  It's needed for 16 bit Windows C
programming and still exists, but is a no-op, for 32 bit Windows C
programming.  What it does in 16 bit Windows C programs is create a
"thunk", a small piece of dynamically created code, and then it 
returns the address of the thunk.  When your program calls the thunk,
the thunk code sets the DS (data segment) register to the right value
and then branches to the function for which MakeProcInstance was originally
called.  This all ties into the C "large model" where 16-bit programs
can have more than one 64K byte data segment.  It all goes away with
32 bit Windows.

In Ada MakeProcInstance may not be necessary, even on 16 bit Windows, because 

- Alsys requires that only top-level subprograms be used for 
  callbacks.  This means library subprograms or subprograms declared
  at the outer level of a library package.

- I *think* I recall that Alsys has just one 64K global data segment,
  not multiple segments like large model C.  

I'm not sure about the second point, you should ask Alsys.

	Mitch Gart



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Windows Programming With ActiveAda for Win32s
@ 1995-03-24 19:41 John Lo
  0 siblings, 0 replies; 5+ messages in thread
From: John Lo @ 1995-03-24 19:41 UTC (permalink / raw)


charliel@ansel.intersource.com (Charlie Lenahan) writes:

>We are trying to Use ActiveAda for Windows 5.1.3 to Create a Dialog Box. 
>Regular Windows Programming you must use a call to MakeProcINstance before you
>call CreateDialog(). How do you Get around this by using the address of the 
>callback function for that dialog box.
>
>Inst:Handle:=GetModuleHandle(C_NULL);
>
>DlgHnd:Hwnd;
>
>Dlgproc:lpvoid:=package.dlg_proc'address;
>
>prt : hwnd;
>
>begin
>
>prt := CreateWindowEx();
>
>dlghnd := CreateDialog(inst, CString("dialog_name"), prt, Convert(DlgProc));
>
>...
>
>end;
>
>.rc file ...
>DIALOG dialog_name ...
>
>This is the general concept we have been attempting.  The dlghnd is not created
>and a call to GetLastError returns 87 - Invalid Parameter.  What are we doing wrong???
>

I assume your stated .rc file content has a typo. It should be:
  dialog_name DIALOG ...

Anyway, I suspect you .rc file may #include a .h header file which defines 
dialog_name to some constant value, eg. "#define dialog_name 200". Thus the 
dialog template has the resource ID of 200 and not the C string "dialog_name".

To specify resource template ID of 200 in your call to CreateDialog, you need 
something like:

    function MAKEINTRESOURCE is
      new UNCHECKED_CONVERSION (INTEGER, LPCTSTR);

and then

    dlghnd := CreateDialog(inst, MAKEINTRESOURCE(200), prt, Convert(DlgProc));

Alternatively, if you remove "#define dialog_name 200" from you .h header 
file, the resource template ID will become "dialog_name" and your code should 
work as is.

John Lo



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Windows Programming With ActiveAda for Win32s
@ 1995-03-24 19:51 John Lo
  0 siblings, 0 replies; 5+ messages in thread
From: John Lo @ 1995-03-24 19:51 UTC (permalink / raw)


charliel@ansel.intersource.com (Charlie Lenahan) writes:

>We are trying to Use ActiveAda for Windows 5.1.3 to Create a Dialog Box. 
>Regular Windows Programming you must use a call to MakeProcINstance before you
>call CreateDialog(). How do you Get around this by using the address of the 
>callback function for that dialog box.
>

As for the issue of MakeProcINstance, this is what Win32 API Reference
(which is included on-line with ActivAda for Windows) says:

"The MakeProcInstance function is obsolete. Win32 functions can be called
directly. This function is provided in Win32 only for compatibility with 
earlier versions of Windows. Win32 applications should not use this 
function." 

John Lo



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1995-03-24 19:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-24 19:41 Windows Programming With ActiveAda for Win32s John Lo
  -- strict thread matches above, loose matches on Subject: below --
1995-03-24 19:51 John Lo
1995-03-21 18:32 Charlie Lenahan
1995-03-22 14:59 ` jjj@sage.inel.gov
1995-03-24 12:39 ` Mitch Gart

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