* Problem w/ Win NT Apex or just me? @ 1998-10-16 0:00 Roga Danar 1998-10-16 0:00 ` Sune Falck 1998-10-17 0:00 ` David C. Hoos, Sr. 0 siblings, 2 replies; 9+ messages in thread From: Roga Danar @ 1998-10-16 0:00 UTC (permalink / raw) 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: ******************** C program *************************** #include <stdio.h> #include <stdlib.h> main (void) { puts ("Starting to print"); system ("print disk_file.txt"); } ************* Ada standalone procedure *************************** -- -- File Name: printer.2.ada -- with Ada.Text_Io; use Ada.Text_Io; -- with Win_Show; procedure Printer is -- pragma Link_With ("pr.o"); Lpt1 : constant String := "LPT1"; Prn : constant String := "PRN"; Net_Printer : constant String := "\\COMPAQ_5\LAB"; Disk_File : constant String := "c:\Disk_File"; File_Buf, File_Buf2, File_Buf3, Disk_Buf : File_Type; -- -- procedure Print; pragma Interface (C, Print); pragma Interface_Name (Print, "_main"); begin begin begin Open (File => Disk_Buf, Mode => Out_File, Name => Disk_File); Put_Line("Opening Disk File"); exception when others => 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 Mode_Error => Put_Line ("Mode Error"); when others => Put_Line ("Disk File test failed"); end; ---------------------------------------------------- --- begin -- LPT Test if not Is_Open (File_Buf) then Open (File => File_Buf, Mode => Out_File, Name => Lpt1); end if; Put_Line (File_Buf, " Testing LPT1 "); New_Page (File_Buf); Close (File_Buf); exception when Name_Error => Put_Line ("LPT1 Name Error"); when Use_Error => Put_Line ("LPT1 Use Error"); when others => Put_Line (" LPT1 failed "); end; --------------------------------------------------------- --- begin -- PRN Test Open (File => File_Buf2, Mode => Out_File, Name => Prn); Put_Line (File_Buf2, " Testing PRN "); New_Page (File_Buf2); Close (File_Buf2); exception when Name_Error => Put_Line ("PRN Name Error"); when Use_Error => Put_Line ("PRN Use Error"); when others => Put_Line (" PRN failed "); end; ---------------------------------------------------------- --- begin -- Net Printer Open (File => File_Buf3, Mode => Out_File, Name => Net_Printer); Put_Line (File_Buf3, " Testing Net Printer "); New_Page (File_Buf3); Close (File_Buf); exception when Mode_Error => Put_Line ("Mode Error"); when others => Put_Line (" Net Printer test failed "); end; --------------------------------------------------------- -- C printing Print; exception when Use_Error => Put_Line (" USE Error "); when others => Put_Line (" Something BAD went wrong !!"); end Printer; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-16 0:00 Problem w/ Win NT Apex or just me? Roga Danar @ 1998-10-16 0:00 ` Sune Falck 1998-10-16 0:00 ` Roga Danar 1998-10-16 0:00 ` Roga Danar 1998-10-17 0:00 ` David C. Hoos, Sr. 1 sibling, 2 replies; 9+ messages in thread From: Sune Falck @ 1998-10-16 0:00 UTC (permalink / raw) This works with ObjectAda and gnat for Windows 95. with ada.text_io; use ada.text_io; procedure ptest is printer : file_type; begin create (printer, out_file, "lpt1:"); put_line (printer,"Test of printing" put_line (printer,"End of test"); new_page (printer); end ptest; Roga Danar skrev i meddelandet <36278110.66641D91@stelnj.com>... >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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-16 0:00 ` Sune Falck @ 1998-10-16 0:00 ` Roga Danar 1998-10-16 0:00 ` Roga Danar 1 sibling, 0 replies; 9+ messages in thread From: Roga Danar @ 1998-10-16 0:00 UTC (permalink / raw) To: Sune Falck Sune, Thanks for the reply. The problem exist w/ WinNT, however. I have no problem running from Win95 either. WinNT holds the ports so that one cannot appearently get at them accept through an API. Actually I am still interested to find out why I have a problem w/ the pragma interface. If you could try that test and let me know what you come up with that would be great. Thanks in advance. Michael Sune Falck wrote: > This works with ObjectAda and gnat for Windows 95. > > with ada.text_io; > use ada.text_io; > procedure ptest is > printer : file_type; > begin > create (printer, out_file, "lpt1:"); > put_line (printer,"Test of printing" > put_line (printer,"End of test"); > new_page (printer); > end ptest; > > Roga Danar skrev i meddelandet <36278110.66641D91@stelnj.com>... > >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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-16 0:00 ` Sune Falck 1998-10-16 0:00 ` Roga Danar @ 1998-10-16 0:00 ` Roga Danar 1998-10-18 0:00 ` Dmitriy Anisimkov 1 sibling, 1 reply; 9+ messages in thread From: Roga Danar @ 1998-10-16 0:00 UTC (permalink / raw) To: Sune Falck Hi, I tried the test on GNAT Ada95 on WinNT and it printed to the local printer fine but the network printer test failed. I guess I am still a bit confused. Also, the pragma import test STILL did not work. This time the program hung and did not complete. -- Michael Sune Falck wrote: > This works with ObjectAda and gnat for Windows 95. > > with ada.text_io; > use ada.text_io; > procedure ptest is > printer : file_type; > begin > create (printer, out_file, "lpt1:"); > put_line (printer,"Test of printing" > put_line (printer,"End of test"); > new_page (printer); > end ptest; > > Roga Danar skrev i meddelandet <36278110.66641D91@stelnj.com>... > >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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-16 0:00 ` Roga Danar @ 1998-10-18 0:00 ` Dmitriy Anisimkov 0 siblings, 0 replies; 9+ messages in thread From: Dmitriy Anisimkov @ 1998-10-18 0:00 UTC (permalink / raw) To: smithm Hi, you wrote: > Also, the pragma import test STILL did not work. This time the program > hung and did not complete. I have look to the Ada95 RM and have no pragma Interface. > procedure Print; > pragma Interface (C, Print); > pragma Interface_Name (Print, "_main"); The legal way to link with the other language modules is : procedure Print; pragma Import (C, Print, "_main"); And I think that using the name "_main" is dangerous becouse some compilers, GNAT for example, uses that name internally. Dmitriy. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-16 0:00 Problem w/ Win NT Apex or just me? Roga Danar 1998-10-16 0:00 ` Sune Falck @ 1998-10-17 0:00 ` David C. Hoos, Sr. 1998-10-17 0:00 ` Tom Moran 1998-10-19 0:00 ` Roga Danar 1 sibling, 2 replies; 9+ messages in thread From: David C. Hoos, Sr. @ 1998-10-17 0:00 UTC (permalink / raw) -----Original Message----- From: Roga Danar <smithm@stelnj.com> 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 <stdio.h> #include <stdlib.h> 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; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-17 0:00 ` David C. Hoos, Sr. @ 1998-10-17 0:00 ` Tom Moran 1998-10-18 0:00 ` David C. Hoos, Sr. 1998-10-19 0:00 ` Roga Danar 1 sibling, 1 reply; 9+ messages in thread From: Tom Moran @ 1998-10-17 0:00 UTC (permalink / raw) > exception > when E: others => > Ada.Exceptions.Raise_Exception > (E => Ada.Exceptions.Exception_Identity (E), > Message => "raised when attempting to open ... Are you sure the open (actually Create) is the only possible source of exceptions here? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-17 0:00 ` Tom Moran @ 1998-10-18 0:00 ` David C. Hoos, Sr. 0 siblings, 0 replies; 9+ messages in thread From: David C. Hoos, Sr. @ 1998-10-18 0:00 UTC (permalink / raw) Tom Moran wrote in message <36290663.18049121@SantaClara01.news.InterNex.Net>... >> exception >> when E: others => >> Ada.Exceptions.Raise_Exception >> (E => Ada.Exceptions.Exception_Identity (E), >> Message => "raised when attempting to open ... >Are you sure the open (actually Create) is the only possible source of >exceptions here? No, of course not. The exception handled (and re-raised) here can be from Open (with any other exception except Name_Error), from Create, Put_Line or Close. The purpose here was not to completely re-wrire his program -- so I kept its basic structure (including its structural flaws), and simply illustrated how to be a little more elegant with informing of exceptions. "Real" code I write would get a hard-copy desk check, rather than just looking at the code on the screen -- which is what happened here. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Problem w/ Win NT Apex or just me? 1998-10-17 0:00 ` David C. Hoos, Sr. 1998-10-17 0:00 ` Tom Moran @ 1998-10-19 0:00 ` Roga Danar 1 sibling, 0 replies; 9+ messages in thread From: Roga Danar @ 1998-10-19 0:00 UTC (permalink / raw) To: David C. Hoos, Sr. 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 <smithm@stelnj.com> > 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 <stdio.h> > #include <stdlib.h> > > 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; ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1998-10-19 0:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1998-10-16 0:00 Problem w/ Win NT Apex or just me? Roga Danar 1998-10-16 0:00 ` Sune Falck 1998-10-16 0:00 ` Roga Danar 1998-10-16 0:00 ` Roga Danar 1998-10-18 0:00 ` Dmitriy Anisimkov 1998-10-17 0:00 ` David C. Hoos, Sr. 1998-10-17 0:00 ` Tom Moran 1998-10-18 0:00 ` David C. Hoos, Sr. 1998-10-19 0:00 ` Roga Danar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox