Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CopyFile API Problems with HP LaserJet 4000
Message
From
05/03/2004 11:27:49
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00883253
Message ID:
00883523
Views:
7
Ok, here is program that tests it and copyfile returns 0 when printing to the hp laserjet 4000, but the line:

liNewErr = FormatMessage(0x1000;
,.NULL., lnErrorCode, 0, @lcErrBuffer,500,0)

in apierror errors out with: 'Data Type Mismatch'

Here is my code:
(Any ideas? Is it in format message? Am I declaring formatmessage wrong maybe? I couldn't find another example...)
*--TCH 03/04/2004
*--Print Using API
DO printfile WITH "C:\foxpro\vfp8\tmpltr.txt"
RETURN


PROCEDURE printfile
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

SET PRINTER TO NAME GETPRINTER()

PRIVATE rcptprinter
rcptprinter = SET('PRINTER',3)

PRIVATE lcsafety
lcsafety = SET('SAFETY')
SET SAFETY OFF

DECLARE INTEGER GetLastError IN WIN32api 
 
DECLARE INTEGER CopyFile IN KERNEL32.DLL ;
   STRING @SourceFileName, ;
   STRING @DestFileName, ;
   INTEGER bFailIfExists

PRIVATE lresult
lresult=CopyFile(@rcptfile,@rcptprinter,0)
IF lresult = 0
	PRIVATE lnewresult
	lnewresult = Apierror(ALLTRIM(STR(GetLastError())))
	IF TYPE('lnewresult')="C"
		WAIT WINDOW lnewresult
	ELSE
		WAIT WIND ALLTRIM(STR(lnewresult))
	ENDIF
   llreturn = .F.
ENDIF

IF TYPE('lcsafety')="C" .and. INLIST(lcsafety,'OFF','ON')
	SET SAFETY &lcsafety
ENDIF

CLEAR DLLS 'CopyFile'

RETURN llreturn

FUNCTION Apierror(tnErrorCode)

DECLARE INTEGER FormatMessage IN kernel32; 
    INTEGER   dwFlags,; 
    INTEGER   lpSource,; 
    INTEGER   dwMessageId,; 
    INTEGER   dwLanguageId,; 
    INTEGER @ lpBuffer,; 
    INTEGER   nSize,; 
    INTEGER   Arguments 
    
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
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform