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,WEIRD_QUOTING autolearn=ham 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: Roga Danar Subject: Re: Problem w/ Win NT Apex or just me? Date: 1998/10/19 Message-ID: <362B5B5A.BB2F024E@nospam.com> X-Deja-AN: 402816671 Content-Transfer-Encoding: 7bit References: <36278110.66641D91@stelnj.com> To: "David C. Hoos, Sr." Content-Type: text/plain; charset=us-ascii X-Trace: news1.exit109.com 908807331 15576 208.225.73.22 (19 Oct 1998 14:28:51 GMT) Organization: AlphaSoft, Inc. Mime-Version: 1.0 Reply-To: nospam@nospam.com NNTP-Posting-Date: 19 Oct 1998 14:28:51 GMT Newsgroups: comp.lang.ada Date: 1998-10-19T14:28:51+00:00 List-Id: David, Thanks for taking the time to try to help me with my problem. However, the solution did not work for Rational Apex Ada because it claims that the object file cannot be resolved. I compiled the pr.c with the GNAT command: "gcc pr.c -c". This does create an object file. I am wondering if I am doing something wrong (again) or if there may be some incompatiblity of which I am not aware. Also, you may have seen my posting about how the previous version of the code (with the OPEN instead of the CREATE) worked w/ GNAT Ada. Do you have any thoughts on this? Thanks in advance. David C. Hoos, Sr. wrote: > -----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;