Taking a Print

This is a discussion on Taking a Print within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, I have attached my code alongwith this query. The problem I am facing is, that although the the ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    39

    Unhappy Taking a Print

    Hi all,

    I have attached my code alongwith this query.

    The problem I am facing is, that although the the code seems to work fine it doesn't actualy cause the printer to take a printout.
    for my application, i am using a postscript printer which will generate a .ps type of file which can then be converted to .pdf
    The local printer has been succesfuly installed and is working well.
    but when I run my program, i simply picks the data from text1.txt and pastes it onto the output file. There is no sign of any postscript headers or footers which means that it is unable to force the printer to take a print.

    I am unable to figure out what is wrong.
    Kindly help.
    Thanks
    Attached Files Attached Files

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    some debugging / error checking would help...


    If a function fails (the return is zero in most cases) then call GetLastError().
    Look up the number in help to get an idea of why ie 87 = incorrect param

    I would be looking at...

    pinfo4 = malloc (dwNeeded) ;
    (always check memory allocations)
    (How much are you allocating, more than one pinfo in size?)

    what is the return value from

    OpenPrinter(pinfo4->pPrinterName,&hHandle,NULL);
    (Is there a valid name in pinfo4->pPrinterName and does hHandle get a value?)

    did you write any thing to the printer?

    WritePrinter(hHandle,buff,sizeof(buff),&dwBytes);
    (did dwBytes get a value)
    (what is sizeof(buff)?)


    I have had trouble with truncated printer names (not enough space to hold the full name then printer fails to open)

    I also use PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL

    I use print info 2 rather than print info 4
    (but have forgotten why...surely I had a good reason...then again..)


    Post again if you still need help.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    39

    Post

    If a function fails (the return is zero in most cases) then call GetLastError().
    Look up the number in help to get an idea of why ie 87 = incorrect param
    I agree, I have now added some error checking into my code. Infact I decided to use Formatmessage(); as a separate header file so that I get a clear message of what is wrong(or right)

    pinfo4 = malloc (dwNeeded) ;
    (always check memory allocations)
    (How much are you allocating, more than one pinfo in size?)
    I am not sure...I just followed the instructions given in MSDN and set the parameters pPrinterEnum = NULL, and cbBuf = 0. As a result the required buffer size is automatically reflected in pcbNeeded.
    (SDK doc of Enumprinters())


    what is the return value from
    OpenPrinter(pinfo4->pPrinterName,&hHandle,NULL);
    (Is there a valid name in pinfo4->pPrinterName and does hHandle get a value?)
    Yes...
    pPrinterName does hold a valid name and i crosschecked it with the name of the printer installed.
    The hHandle also gets a value.
    and The the error checking returned "Operation completed succesfully"

    did you write any thing to the printer?
    WritePrinter(hHandle,buff,sizeof(buff),&dwBytes);
    (did dwBytes get a value)
    (what is sizeof(buff)?)
    sizeof(buff) shows the same value i allocated to buff[] i.e. 1030656 (close to 1mb)
    dwBytes also shows the same value as sizeof(buff).
    I am sure there is some value in buff[], b'coz i even tried simply writing this data to another .doc file and it works

    After the WritePrinter command I get this error message:
    "The specified resource type cannot be found in the image file"
    can't figure out what that means.

    I also use PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL
    I have two printers installed on my PC and the "post script" printer has been set as default. When I use the above combination, the code tries to select the other (network printer) which in my case is not desirable. So i guess i won't work for me

    I use print info 2 rather than print info 4
    I will try that out also and let you know the results...

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>the same value i allocated to buff[] i.e. 1030656

    make sure you allow space for the terminator character in the buffer.

    better to dynamic alloc the mem = file size + 1
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure to function (to print)
    By hello234 in forum C Programming
    Replies: 11
    Last Post: 11-02-2008, 01:58 PM
  2. Need help to print even numbers
    By ortegac in forum C Programming
    Replies: 3
    Last Post: 05-21-2006, 12:01 AM
  3. Replies: 14
    Last Post: 01-12-2006, 04:08 AM
  4. Bypassing Print Dialog Box
    By leojose in forum Windows Programming
    Replies: 0
    Last Post: 10-13-2005, 06:44 AM
  5. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21