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:05:11
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00883253
Message ID:
00883507
Views:
12
Hahahaha, silly me. It just dawned on me the datatype mismatch was because I was sending a numeric type to a wait window... sheesh, where is my mind today? :o) Now I just have to do a search on what error#53 means when returned from that api call...


I'm obviously doing something wrong because I get a datatype mismatch using getlasterror and then it returns '53.'
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 GetLastError IN kernel32
 
DECLARE INTEGER FormatMessage IN kernel32; 
    INTEGER   dwFlags,; 
    INTEGER   lpSource,; 
    INTEGER   dwMessageId,; 
    INTEGER   dwLanguageId,; 
    INTEGER @ lpBuffer,; 
    INTEGER   nSize,; 
    INTEGER   Arguments 

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

IF CopyFile(@rcptfile,@rcptprinter,0) # 0
   llreturn = .T.
ELSE
   WAIT WIND Apierror(GetLastError())
   llreturn = .F.
ENDIF

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


RETURN llreturn



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
Tracy

>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
>>
>>
.·*´¨)
.·`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