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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, WEIRD_QUOTING autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7cbbcde0157485b2 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Problem w/ Win NT Apex or just me? Date: 1998/10/17 Message-ID: #1/1 X-Deja-AN: 402252764 References: <36278110.66641D91@stelnj.com> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1998-10-17T00:00:00+00:00 List-Id: -----Original Message----- From: Roga Danar Newsgroups: comp.lang.ada Date: Friday, October 16, 1998 12:23 PM Subject: Problem w/ Win NT Apex or just me? >Hi, > > I have been attempting to write an Apex Ada95 program that will print >from WIN NT w/ using the WIN API, just as a test. > > The following code fails on each block, but I expected that. > But I am confused why the pragma interface to a C program is not >working either. > > The program finishes but no printing happens. > > I am not sure what if anything I am doing incorrectly. I am sure it >will be pointed out if I am. > > If someone could help me out it would be great. > The 'C' code and Ada code follows: The fundamental problem is that when "opening" the printers on WinNT, you need to Create instead of Open. The attached code works in all five blocks on my machine. You'll have to change the name of the network printer accordingly. There were two problems beside the use of Create instead of Open, viz.: 1.. The name of your C routine cannot be "main" in the gnat environment, for gnat has a C "main" wrapped around everything. I changed it to "pr" 2. After printing to the Network Printer, you attempted to close File_buf, instead of File_Buf3. In addition to making it work, I have illustrated a more elegant exception handling mechanism, utilizing the Ada95 predefined Ada.Exceptions package. David C. Hoos, Sr. #include #include pr (void) { puts ("starting to print"); system ("print disk_file.txt"); }with Ada.Exceptions; with Ada.Text_Io; use Ada.Text_Io; -- with Win_Show; procedure Printer is pragma Linker_Options ("pr.o"); Lpt1 : constant String := "LPT1"; Prn : constant String := "PRN"; Net_Printer : constant String := "\\DHOOSSR\HP-LJ5P"; Disk_File : constant String := "c:\temp\Disk_File"; File_Buf, File_Buf2, File_Buf3, Disk_Buf : File_Type; -- -- procedure Print; pragma Interface (C, Print); pragma Interface_Name (Print, "pr"); begin begin begin Open (File => Disk_Buf, Mode => Out_File, Name => Disk_File); Put_Line("Opening Disk File"); exception when Ada.Text_Io.Name_Error => Create (File => Disk_Buf, Mode => Out_File, Name => Disk_File); Put_Line ("creating file"); end; Put_Line (Disk_Buf, "Testing Disk File"); Close (Disk_Buf); exception when E: others => Ada.Exceptions.Raise_Exception (E => Ada.Exceptions.Exception_Identity (E), Message => "raised when attempting to open """ & Disk_File & """"); end; ---------------------------------------------------- --- begin -- LPT Test Create (File => File_Buf, Mode => Out_File, Name => Lpt1); Put_Line (File_Buf, " Testing LPT1 "); New_Page (File_Buf); Close (File_Buf); exception when E: others => Ada.Exceptions.Raise_Exception (E => Ada.Exceptions.Exception_Identity (E), Message => "raised when attempting to create """ & Lpt1 & """"); end; --------------------------------------------------------- --- begin -- PRN Test Create (File => File_Buf2, Mode => Out_File, Name => Prn); Put_Line (File_Buf2, " Testing PRN "); New_Page (File_Buf2); Close (File_Buf2); exception when E: others => Ada.Exceptions.Raise_Exception (E => Ada.Exceptions.Exception_Identity (E), Message => "raised when attempting to create """ & Prn & """"); end; ---------------------------------------------------------- --- begin -- Net Printer Create (File => File_Buf3, Mode => Out_File, Name => Net_Printer); Put_Line (File_Buf3, " Testing Net Printer "); New_Page (File_Buf3); Close (File_Buf3); exception when E: others => Ada.Exceptions.Raise_Exception (E => Ada.Exceptions.Exception_Identity (E), Message => "raised when attempting to create """ & Net_Printer & """"); end; --------------------------------------------------------- -- C printing Print; exception when E: others => Put_Line (Ada.Exceptions.Exception_Information (E)); end Printer;