Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CopyFile API Problems with HP LaserJet 4000
Message
 
 
To
04/03/2004 15:38:40
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00883253
Message ID:
00883304
Views:
20
Hi Tracy,

You can get extended error information using GetLastError function
DECLARE Long GetLastError IN kernel32
Declare Long FormatMessage In kernel32.dll as FormatMessage ;
		Long dwFlags, String @lpSource, Long dwMessageId, ;
		Long dwLanguageId, String @lpBuffer, Long nSize, ;
		Long Arguments
...
IF CopyFile(@rcptfile,@rcptprinter,0) # 0
   llreturn = .T.
ELSE
   llreturn = .F.
   * Test code
   WAIT WIND Apierror(GetLastError)
ENDIF
...

FUNCTION Apierror(tnErrorCode)
Local lcErrBuffer, lcErrorMess, liNewErr, lnErrorCode
lcErrBuffer = REPL(CHR(0),1000)
lnErrorCode = tnErrorCode
liNewErr = FormatMessage(0x1000;
	 	,.NULL., lnErrorCode, 0, @lcErrBuffer,500,0)
lcErrorMess = Transform(lnErrorCode) + "    " + LEFT(lcErrBuffer, AT(CHR(0),lcErrBuffer)- 1 )
RETURN lcErrorMess
>I use the below program successfully passing a filename and printing to an Okidata ML320 and other dot matrix printers on the network. I was testing this for other reasons in the past. Today I wanted to print to an HP laserjet 4000 on the network and it bombed. It returns a zero and the file does not print. Both are network printers. Both print successfully in VFP using SET PRINTER TO NAME ... fine in all other ways that I print except using copyfile api. Any ideas?
>
>TIA,
>Tracy
>
>*--TCH 03/04/2004
>*--Print Using API
>PARAMETERS lcfile
>
>IF TYPE('lcfile')<>"C" .or. EMPTY(lcfile) .or. !FILE(lcfile)
>	=OKAY('The report file was not created.  An error occured.')
>	RETURN .F.
>ENDIF
>
>PRIVATE llreturn
>llreturn = .T.
>
>PRIVATE rcptfile
>rcptfile = lcfile
>PRIVATE rcptprinter
>rcptprinter = SET('PRINTER',3)
>
>PRIVATE lcsafety
>lcsafety = SET('SAFETY')
>SET SAFETY OFF
>
>DECLARE INTEGER CopyFile IN KERNEL32.DLL ;
>   STRING @SourceFileName, ;
>   STRING @DestFileName, ;
>   INTEGER bFailIfExists
>IF CopyFile(@rcptfile,@rcptprinter,0) # 0
>   llreturn = .T.
>ELSE
>   llreturn = .F.
>ENDIF
>
>IF TYPE('lcsafety')="C" .and. INLIST(lcsafety,'OFF','ON')
>	SET SAFETY &lcsafety
>ENDIF
>
>CLEAR DLLS 'CopyFile'
>
>RETURN llreturn
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform