From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Problem w/ Win NT Apex or just me?
Date: 1998/10/17
Date: 1998-10-17T00:00:00+00:00 [thread overview]
Message-ID: <NIMJmmg#9GA.70@samson.airnet.net> (raw)
In-Reply-To: 36278110.66641D91@stelnj.com
-----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;
next prev parent reply other threads:[~1998-10-17 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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. [this message]
1998-10-17 0:00 ` Tom Moran
1998-10-18 0:00 ` David C. Hoos, Sr.
1998-10-19 0:00 ` Roga Danar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox