Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-17-2005, 04:56 AM   #1 (permalink)
the_ruthless
Registered User
 
Join Date: Mar 2005
Posts: 6
the_ruthless is on a distinguished road
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
the_ruthless is offline   Reply With Quote
Old 03-17-2005, 06:28 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
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;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-17-2005, 07:56 AM   #3 (permalink)
the_ruthless
Registered User
 
Join Date: Mar 2005
Posts: 6
the_ruthless is on a distinguished road
thx i will try this in a few minutes
the_ruthless is offline   Reply With Quote
Old 03-17-2005, 08:32 AM   #4 (permalink)
the_ruthless
Registered User
 
Join Date: Mar 2005
Posts: 6
the_ruthless is on a distinguished road
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*)
the_ruthless is offline   Reply With Quote
Old 03-18-2005, 12:16 AM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
then try changing:
Code:
int PrintHPFile( const char *filename )
{
..
to
Code:
int PrintHPFile( char *filename )
{
...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-19-2005, 12:11 AM   #6 (permalink)
the_ruthless
Registered User
 
Join Date: Mar 2005
Posts: 6
the_ruthless is on a distinguished road
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
the_ruthless is offline   Reply With Quote
Old 03-19-2005, 02:28 AM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
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 ??
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-19-2005, 02:41 AM   #8 (permalink)
the_ruthless
Registered User
 
Join Date: Mar 2005
Posts: 6
the_ruthless is on a distinguished road
yeah no it was idd e fault in my main
now i got 2 figure out how to use that PrintHPFile(char *filename ) thingie
the_ruthless is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 03:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting