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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5feb723c26279aee,start X-Google-Attributes: gid103376,public From: John English Subject: Win32 dialogs/resource grief (longish) Date: 2000/03/01 Message-ID: <38BC8428.901597BD@brighton.ac.uk> X-Deja-AN: 591585406 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: news@bton.ac.uk X-Trace: saturn.bton.ac.uk 951878393 11864 194.81.199.188 (1 Mar 2000 02:39:53 GMT) Organization: University of Brighton Mime-Version: 1.0 NNTP-Posting-Date: 1 Mar 2000 02:39:53 GMT Newsgroups: comp.lang.ada Date: 2000-03-01T02:39:53+00:00 List-Id: I have a problem with an apparent bug to do with using resources with the Win32 binding -- long post, sorry, but it's stripped as far down as I can manage. I'm using Gnat 3.12 here. Any advice *much* appreciated -- I'm running out of walls to bang my head against :-( I have two simple dialogs: one with a label, combo box and OK/Cancel buttons, another with a label and Yes/No/Cancel buttons. They work fine individually, but not together. I've tried putting the dialogs in the same resource file and in separate files; it makes no difference. The test program (test_dialogs.adb) looks like this: with Test_YesNo; -- 1 with Test_Combo; -- 2 procedure Test_Dialogs is begin Test_YesNo.Do_Dialog; -- 3 Test_Combo.Do_Dialog; -- 4 end Test_Dialogs; The Yes/No dialog fails unless both lines 2 and 4 are commented out. Commenting out line 4 only has no effect. I've also seen the combo box dialog fail unless lines 1 and 3 are commented out. The fact that the "with" clause needs to be commented out strikes me as significant, but I don't know exactly what it signifies -- any ideas, anyone? Using "GetLastError" and "FormatError" to find out what the error in the call to DialogBox is, I get one of two messages: "The specified procedure could not be found", or more puzzlingly, "The operation completed successfully" (this when DialogBox returns -1 to signify failure!). The resources were compiled using the Borland resource compiler "brcc32" from the BC++ 5.02 distribution and converted to COFF files using res2coff from Gnat 3.12. Here's the compilation sequence: brcc32 combodlg.rc res2coff -i combodlg.res -o combodlg.o brcc32 yesnodlg.rc res2coff -i yesnodlg.res -o yesnodlg.o gnatmake test_dialogs.adb The packages specs referenced on lines 1 and 2 of Test_Dialogs are as follows: package Test_Combo is procedure Do_Dialog; end Test_Combo; package Test_YesNo is procedure Do_Dialog; end Test_YesNo; The bodies are as follows: with Win32, Win32.WinMain, Win32.WinDef, Win32.WinUser, Ada.Text_IO, System, Interfaces.C, Test_Common; use Test_Common; package body Test_Combo is pragma Linker_Options("combodlg.o"); use type Win32.Char_Array; COMBOBOX : constant := 1020; -- combobox control ID from combodlg.rc function ComboDlg_Handler (hwnd : Win32.WinDef.HWND; msg : Win32.UINT; wParam : Win32.WPARAM; lParam : Win32.LPARAM) return Win32.BOOL; pragma Convention (Stdcall, ComboDlg_Handler); Result : Integer; Options : constant array (1..3) of Win32.Char_Array(1..6) := ("Yes " & Win32.NUL, "No " & Win32.NUL, "Maybe" & Win32.NUL); function ComboDlg_Handler (hwnd : Win32.WinDef.HWND; msg : Win32.UINT; wParam : Win32.WPARAM; lParam : Win32.LPARAM) return Win32.BOOL is Dummy : Win32.LRESULT; begin case msg is when Win32.WinUser.WM_INITDIALOG => for I in Options'Range loop Dummy := Win32.WinUser.SendMessage (Win32.WinUser.GetDlgItem(hwnd,COMBOBOX), Win32.WinUser.CB_ADDSTRING, 0, CP(Options(I))); end loop; return Win32.TRUE; when Win32.WinUser.WM_COMMAND => case wParam is when Win32.WinUser.IDOK => Result := Integer(Win32.WinUser.SendMessage (Win32.WinUser.GetDlgItem(hwnd,COMBOBOX), Win32.WinUser.CB_GETCURSEL, 0, 0)); return Win32.WinUser.EndDialog (hwnd, Win32.TRUE); when Win32.WinUser.IDCANCEL => return Win32.WinUser.EndDialog (hwnd, Win32.FALSE); when others => return Win32.FALSE; end case; when others => return Win32.FALSE; end case; end ComboDlg_Handler; procedure Do_Dialog is I : Interfaces.C.Int; begin Ada.Text_IO.Put_Line ("--- Combo box dialog test ---"); I := Win32.WinUser.DialogBox (Win32.WinMain.Get_hInstance, CP("ComboDlg"), System.Null_Address, ComboDlg_Handler'Access); Ada.Text_IO.Put_Line ("Return value:" & Integer'Image(Integer(I))); Ada.Text_IO.Put_Line ("Result:" & Integer'Image(Result)); end Do_Dialog; end Test_Combo; with Win32, Win32.WinDef, Win32.WinMain, Win32.WinUser, Interfaces.C, Ada.Text_IO, Ada.Unchecked_Conversion, System, Test_Common; use Test_Common; package body Test_YesNo is pragma Linker_Options("yesnodlg.o"); use type Interfaces.C.Unsigned; function YesNoDlg_Handler (hwnd : Win32.WinDef.HWND; msg : Win32.UINT; wParam : Win32.WPARAM; lParam : Win32.LPARAM) return Win32.BOOL; pragma Convention (Stdcall, YesNoDlg_Handler); Result : Boolean; function YesNoDlg_Handler (hwnd : Win32.WinDef.HWND; msg : Win32.UINT; wParam : Win32.WPARAM; lParam : Win32.LPARAM) return Win32.BOOL is begin case msg is when Win32.WinUser.WM_INITDIALOG => return Win32.TRUE; when Win32.WinUser.WM_COMMAND => case wParam is when Win32.WinUser.IDYES | Win32.WinUser.IDNO => Result := (wParam = Win32.WinUser.IDYES); return Win32.WinUser.EndDialog (hwnd, Win32.TRUE); when Win32.WinUser.IDCANCEL => return Win32.WinUser.EndDialog (hwnd, Win32.FALSE); when others => return Win32.FALSE; end case; when others => return Win32.FALSE; end case; end YesNoDlg_Handler; procedure Do_Dialog is I : Interfaces.C.Int; begin Ada.Text_IO.Put_Line ("--- Yes/no dialog test ---"); I := Win32.WinUser.DialogBox (Win32.WinMain.Get_hInstance, CP("YesNoDlg"), System.Null_Address, YesNoDlg_Handler'Access); Ada.Text_IO.Put_Line ("Return value:" & Integer'Image(Integer(I))); Ada.Text_IO.Put_Line ("Result: " & Boolean'Image(Result)); end Do_Dialog; end Test_YesNo; The package Test_Common contains a couple of type conversion routines: with Win32, Interfaces.C; package Test_Common is function CP(C_Str : Win32.CHAR_Array) return Interfaces.C.LONG; function CP(C_Str : Win32.CHAR_Array) return Win32.LPCSTR; end Test_Common; with Win32, System, Interfaces.C, Ada.Unchecked_Conversion; package body Test_Common is use type Interfaces.C.Unsigned_Long; function CP(C_Str : Win32.CHAR_Array) return Interfaces.C.LONG is function UC is new Ada.Unchecked_Conversion (System.Address,Interfaces.C.LONG); begin return UC(C_Str(C_Str'First)'Address); end CP; function CP(C_Str : Win32.CHAR_Array) return Win32.LPCSTR is function UC is new Ada.Unchecked_Conversion (System.Address,Win32.LPCSTR); begin return UC(C_Str(C_Str'First)'Address); end CP; end Test_Common; The resources are defined thusly: /*--- yesnodlg.rc ---*/ YesNoDlg DIALOG 6, 15, 166, 39 STYLE DS_3DLOOK | DS_CENTER | 0x200L | WS_POPUP | WS_VISIBLE | WS_CAPTION CAPTION "Yes/no dialog" FONT 9, "Arial" { LTEXT "Press a button:", 1004, 8, 4, 131, 12 DEFPUSHBUTTON "Yes", IDYES, 12, 20, 42, 13 PUSHBUTTON "No", IDNO, 64, 20, 42, 13 PUSHBUTTON "Cancel", IDCANCEL, 116, 20, 42, 13 } /*--- combodlg.rc ---*/ ComboDlg DIALOG 6, 15, 147, 56 STYLE DS_3DLOOK | DS_CENTER | 0x200L | WS_POPUP | WS_VISIBLE | WS_CAPTION CAPTION "Input required" FONT 9, "Arial" { LTEXT "Choose a value:", 1002, 8, 4, 131, 12 COMBOBOX 1020, 7, 18, 132, 78, CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP DEFPUSHBUTTON "OK", IDOK, 23, 36, 42, 13 PUSHBUTTON "Cancel", IDCANCEL, 83, 36, 42, 13 } Please help! This is driving me mad! ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------