|
 |
|
 |
03-17-2005, 03:56 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
c and printers
hello i'm using borland C
i'm coding a program, that does the following
a user types in a text. he can save this this file or print it but for the secod thing i dont have a clue how to start with that.
so my question is how can i print that saved txt file from C out?
i know it has to do something with streams and i/o but i dont know how to start with it 
i hope someone can help me with that, thanks allot
|
|
|
03-17-2005, 05:28 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
|
Google found this for me:
Code:
#define PRINTDRIVER
#include <windows.h>
#include <string.h>
#include <print.h>
#include <stdio.h>
int PrintHPFile( const char *filename )
{
char *pszPrInfo = new char[ 80 ];
// Get the printer setup string from the ini file
GetProfileString( "windows", "device", ",,,", pszPrInfo, 80 );
// Format of ini file line = <Device,Driver,Port>
char *pszDevice = strtok( pszPrInfo, "," );
char *pszDriver = strtok( NULL, "," );
char *pszPort = strtok( NULL, "," );
// create a printer device context
HDC PrintHandle = CreateDC( pszDriver, pszDevice, pszPort,
NULL );
// get a job handle, allocate a buffer
HPJOB PrintJob;
char *buf = new char[ 1024 ];
// open the file for reading
FILE *hp_file = fopen( filename, "rb" );
// Start the print job
PrintJob = OpenJob( pszPort, filename, (HPJOB)PrintHandle );
StartSpoolPage( PrintJob );
// print the file, 1K at a time
for( size_t i(0);; )
{
i = fread( buf, 1, 1023, hp_file );
if( i>0 )
WriteSpool( PrintJob, buf, i );
else
break;
}
// Close up print job
EndSpoolPage( PrintJob );
CloseJob( PrintJob );
// Clean up
DeleteDC( PrintHandle );
fclose( hp_file );
delete[] pszPrInfo;
delete[] buf;
return 1;
}
|
|
|
03-17-2005, 06:56 AM
|
#3 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
thx i will try this in a few minutes 
|
|
|
03-17-2005, 07:32 AM
|
#4 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
i get a error in borland c++
and it says
error TESTFILE.cpp 32 : cannot convert 'const char*' to 'char *' in function printHPFile(const char*)
error TESTFILE.cpp 32 : Type mismatch in parameter in call to 'pascal OpenJob(char *, char * , unsigned int)' in function printHPFile(const char*)
|
|
|
03-17-2005, 11:16 PM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
|
then try changing:
Code:
int PrintHPFile( const char *filename )
{
..
to
Code:
int PrintHPFile( char *filename )
{
...
|
|
|
03-18-2005, 11:11 PM
|
#6 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
thx redhead for fixing that error 
but now i get a linker error what does that mean??
linker error : undifined symbol main in library file C:\BC45\LIB\cwl.lib in module winmain
i tryed to find it myself first and still trying but i dont know 
|
|
|
03-19-2005, 01:28 AM
|
#7 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,692
|
Quote:
|
Originally Posted by the_ruthless
linker error : undifined symbol main in library file C:\BC45\LIB\cwl.lib in module winmain
|
Don't know what that might point towards.. I've never used the Borland comiler, but from previus experiences this might be because your project needs to be linked to a specific library, with gcc this is accomplished by -l<library> But since it's an undefined symbol, could it be your program dosn't have a main() function ??
|
|
|
03-19-2005, 01:41 AM
|
#8 (permalink)
|
|
Registered User
Join Date: Mar 2005
Posts: 6
|
yeah no it was idd e fault in my main 
now i got 2 figure out how to use that PrintHPFile(char *filename ) thingie 
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 07:35 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|