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?
>*--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 > >