printing from .exe running as a service

printing from .exe running as a service

Postby don lowenstein » Wed Apr 05, 2006 5:22 pm

I have an exe loaded as a service on NT. Many thanks to the help received from this forum in creating exe's to run as a service.

Now, I need this application to print to the default printer. My application uses the tprinter class and the Fivewin report class.

During the print attempt I receive the following message.

MsgStop( "There are no printers installed!" + CRLF + ;
"Please exit this application and install a printer." )

This comes from the printer.prg (tprinter class) from the following lines of code.

if ::hDC != 0
aOffset := PrnOffset( ::hDC )
::nXOffset := aOffset[1]
::nYOffset := aOffset[2]
::nOrient := ::GetOrientation()
elseif ComDlgXErr() != 0
MsgStop( "There are no printers installed!" + CRLF + ;
"Please exit this application and install a printer." )
::nXOffset := 0
::nYOffset := 0
else
::nXOffset := 0
::nYOffset := 0
::nOrient := DMORIENT_PORTRAIT
endif

My question is, how can I utilize the printer class from an application running as a service? Or, how can I "install" a printer which will be available to services that are running?

Thanks in advance.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Postby AngelSalom » Fri Mar 23, 2007 3:18 pm

Can you tell me how you make the application run as a service?
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

run exe as a service

Postby don lowenstein » Fri Mar 23, 2007 4:51 pm

Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Postby James Bott » Mon Mar 26, 2007 4:40 pm

Don,

Search google for this phrase, "printing from windows service" and look at the first article listed. I think it will answer your question.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby don lowenstein » Mon Mar 26, 2007 5:09 pm

Thanks.

Currently I perform my printing using a .pdf tool that I think you may have alerted me about.

Image2PDF.dll -- works wonderfully. I use the FWH report object - modified 2 lines of code to control the location and names of the .emf files, and then convert to .pdf documents and deliver via the web.

I will checkout your link as well.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm

Postby AngelSalom » Tue Mar 27, 2007 6:32 am

Don, thanks for your help. I make the application right, but now i've a problem ...

I've installed the exe as a service with the srvany.

Into the .prg i use these functions :

//------------------------------
Function ServiceProcess( mode )
//------------------------------
Local nProcessId := 0

Default mode := 0

nProcessId := GCP( )

If Abs( nProcessId ) > 0
RSProcess( nProcessId, mode )
Endif

RETURN

//----------------------------------------------------
DLL32 FUNCTION RSProcess(npID AS LONG ,;
nMode AS LONG ) AS LONG ;
FROM "RegisterServiceProcess" LIB "kernel32.DLL"
//----------------------------------------------------

//----------------------------------------------------
DLL32 FUNCTION GCP() AS LONG;
FROM "GetCurrentProcessId" LIB "kernel32.dll"
//----------------------------------------------------

... and in then Function Main()
ServiceProcess(1)


Well, it's allright, but when i try to start the service, i've got an error message : (error 1053 : service is not responding) (windows 2003 server).

Curiously, the application starts (i make a log file in the app and really works), but the service ends and the application is out!


Thanks ... and sorry for my english ! ;-)
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 727
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Postby don lowenstein » Tue Mar 27, 2007 5:50 pm

I think the .exe which is spawned by the service should run continously controlled by some sort of loop or timer. I usually terminate the .exe via a 'trigger' such as writing a txt file from another process to instruct the loop to end.

Note that the srvany.exe service process simply loads yourapplication.exe automatically, upon server startup. It does not continously load the application. If you terminate the .exe the service may still continue to run. Terminating the service will terminate your .exe, but terminating your .exe will not terminate the service necessarily.

I use the service (srvany.exe) as a method to automatically load an exe process upon server startup.
Don Lowenstein
www.laapc.com
User avatar
don lowenstein
 
Posts: 197
Joined: Mon Oct 17, 2005 9:09 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 31 guests