PrintDlg function fails - Programmer

This is a discussion on PrintDlg function fails - Programmer ; Hi, I have a print.C which on compilation results in print.exe. This exe invokes the Windows Printer Dialog Box when PrintDlg function is being called. Before calling PrintDlg function, pd.hDevMode and pd.hDevNames are set to NULL. pd.hDevMode = NULL; pd.hDevNames ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: PrintDlg function fails

  1. PrintDlg function fails


    Hi,
    I have a print.C which on compilation results in print.exe.

    This exe invokes the Windows Printer Dialog Box when PrintDlg function
    is being called.
    Before calling PrintDlg function,
    pd.hDevMode and pd.hDevNames are set to NULL.

    pd.hDevMode = NULL;
    pd.hDevNames = NULL;

    Other members of PRINTDLG pd structure variable are set as follows

    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;

    I have set the PD_RETURNDEFAULT flag as I dont want to see the Printer
    Dialog Box Window.

    After setting these values, PrintDlg function is called as
    if(!PrintDlg(&pd)) {
    fprintf(stderr, "> sprintf(debug_log, "\n 244: printSetup was cancelled");
    debugmsg(debug_log, __LINE__) ;
    fflush(stderr);
    ExitProcess(1);
    }

    When PD_RETURNDEFAULT flag is set, PrintDlg(&pd) function call sets
    the pd.hDevMode and pd.hDevNames to Non NULL values( namely handle to
    global memory object containing DEVMODE and DEVNAMES structures ) . So
    now following check passes

    if (pd.hDevNames == NULL) {
    fprintf(stderr, "> sprintf(debug_log, "\n 251: printSetup failed"); debugmsg(debug_log,
    __LINE__) ;
    fflush(stderr);
    ExitProcess(1);
    }


    Later on some formatting of the lines( to be printed ) is done, where
    non null values of pd.hDevMode and pd.hDevNames are required.

    The code works fine in this case.




    NOW, I wanted to reuse the same file for some different kind of
    formatting.

    So I copied the file print.C to formatPrint.C which on building
    results in formatPrint,exe

    Here also I want to set the PD_RETURNDEFAULT flag as I dont want to
    see the PrintDialog box window.

    pd.hDevMode and pd.hDevNames are again set to NULL.
    Other values also remain the same.

    But here PrintDlg(&pd) function doesn't result in setting of
    pd.hDevMode and pd.hDevNames to non null values.
    As a result the above check fails and ExitProcess is called and I am
    not able to proceed further with my formatting.

    To Troubleshoot it further I had called CommDlgExtendedError() to get
    the error code.
    The error code returned was PDERR_NODEFAULTPRN which is set when no
    default printer is found.

    But the question here is when the source code is the same, why
    PrintDlg succeeds in 1st Case and in second its failing.

    Can any one help me with this.
    If you need any more information, I can provide.

    Thanks in Advance,
    Guddu


  2. Re: PrintDlg function fails

    On Jul 16, 11:21 pm, guddu wrote:
    > Hi,
    > I have a print.C which on compilation results in print.exe.
    >
    > This exe invokes the Windows Printer Dialog Box when PrintDlg function
    > is being called.
    > Before calling PrintDlg function,
    > pd.hDevMode and pd.hDevNames are set to NULL.
    >
    > pd.hDevMode = NULL;
    > pd.hDevNames = NULL;
    >
    > Other members of PRINTDLG pd structure variable are set as follows
    >
    > pd.lStructSize = sizeof(PRINTDLG);
    > pd.hwndOwner = hWnd;
    > pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
    >
    > I have set the PD_RETURNDEFAULT flag as I dont want to see the Printer
    > Dialog Box Window.
    >
    > After setting these values, PrintDlg function is called as
    > if(!PrintDlg(&pd)) {
    > fprintf(stderr, "> > sprintf(debug_log, "\n 244: printSetup was cancelled");
    > debugmsg(debug_log, __LINE__) ;
    > fflush(stderr);
    > ExitProcess(1);
    > }
    >
    > When PD_RETURNDEFAULT flag is set, PrintDlg(&pd) function call sets
    > the pd.hDevMode and pd.hDevNames to Non NULL values( namely handle to
    > global memory object containing DEVMODE and DEVNAMES structures ) . So
    > now following check passes
    >
    > if (pd.hDevNames == NULL) {
    > fprintf(stderr, "> > sprintf(debug_log, "\n 251: printSetup failed"); debugmsg(debug_log,
    > __LINE__) ;
    > fflush(stderr);
    > ExitProcess(1);
    > }
    >
    > Later on some formatting of the lines( to be printed ) is done, where
    > non null values of pd.hDevMode and pd.hDevNames are required.
    >
    > The code works fine in this case.
    >
    > NOW, I wanted to reuse the same file for some different kind of
    > formatting.
    >
    > So I copied the file print.C to formatPrint.C which on building
    > results in formatPrint,exe
    >
    > Here also I want to set the PD_RETURNDEFAULT flag as I dont want to
    > see the PrintDialog box window.
    >
    > pd.hDevMode and pd.hDevNames are again set to NULL.
    > Other values also remain the same.
    >
    > But here PrintDlg(&pd) function doesn't result in setting of
    > pd.hDevMode and pd.hDevNames to non null values.
    > As a result the above check fails and ExitProcess is called and I am
    > not able to proceed further with my formatting.
    >
    > To Troubleshoot it further I had called CommDlgExtendedError() to get
    > the error code.
    > The error code returned was PDERR_NODEFAULTPRN which is set when no
    > default printer is found.
    >
    > But the question here is when the source code is the same, why
    > PrintDlg succeeds in 1st Case and in second its failing.
    >
    > Can any one help me with this.
    > If you need any more information, I can provide.
    >
    > Thanks in Advance,
    > Guddu



    Hi,

    The function PrintDlg() have been superseded by the following API:

    PrintDlgEx()

    So, try to use the new function and see if you still have the same
    issue.

    http://msdn2.microsoft.com/en-us/library/ms646942.aspx

    http://msdn2.microsoft.com/en-us/lib...aspx#print_dlg

    Kellie.



  3. Re: PrintDlg function fails

    On Jul 16, 11:21 pm, guddu wrote:
    > Hi,
    > I have a print.C which on compilation results in print.exe.
    >
    > This exe invokes the Windows Printer Dialog Box when PrintDlg function
    > is being called.
    > Before calling PrintDlg function,
    > pd.hDevMode and pd.hDevNames are set to NULL.
    >
    > pd.hDevMode = NULL;
    > pd.hDevNames = NULL;
    >
    > Other members of PRINTDLG pd structure variable are set as follows
    >
    > pd.lStructSize = sizeof(PRINTDLG);
    > pd.hwndOwner = hWnd;
    > pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
    >
    > I have set the PD_RETURNDEFAULT flag as I dont want to see the Printer
    > Dialog Box Window.
    >
    > After setting these values, PrintDlg function is called as
    > if(!PrintDlg(&pd)) {
    > fprintf(stderr, "> > sprintf(debug_log, "\n 244: printSetup was cancelled");
    > debugmsg(debug_log, __LINE__) ;
    > fflush(stderr);
    > ExitProcess(1);
    > }
    >
    > When PD_RETURNDEFAULT flag is set, PrintDlg(&pd) function call sets
    > the pd.hDevMode and pd.hDevNames to Non NULL values( namely handle to
    > global memory object containing DEVMODE and DEVNAMES structures ) . So
    > now following check passes
    >
    > if (pd.hDevNames == NULL) {
    > fprintf(stderr, "> > sprintf(debug_log, "\n 251: printSetup failed"); debugmsg(debug_log,
    > __LINE__) ;
    > fflush(stderr);
    > ExitProcess(1);
    > }
    >
    > Later on some formatting of the lines( to be printed ) is done, where
    > non null values of pd.hDevMode and pd.hDevNames are required.
    >
    > The code works fine in this case.
    >
    > NOW, I wanted to reuse the same file for some different kind of
    > formatting.
    >
    > So I copied the file print.C to formatPrint.C which on building
    > results in formatPrint,exe
    >
    > Here also I want to set the PD_RETURNDEFAULT flag as I dont want to
    > see the PrintDialog box window.
    >
    > pd.hDevMode and pd.hDevNames are again set to NULL.
    > Other values also remain the same.
    >
    > But here PrintDlg(&pd) function doesn't result in setting of
    > pd.hDevMode and pd.hDevNames to non null values.
    > As a result the above check fails and ExitProcess is called and I am
    > not able to proceed further with my formatting.
    >
    > To Troubleshoot it further I had called CommDlgExtendedError() to get
    > the error code.
    > The error code returned was PDERR_NODEFAULTPRN which is set when no
    > default printer is found.
    >
    > But the question here is when the source code is the same, why
    > PrintDlg succeeds in 1st Case and in second its failing.
    >
    > Can any one help me with this.
    > If you need any more information, I can provide.
    >
    > Thanks in Advance,
    > Guddu



    Hi,

    The function PrintDlg() have been superseded by the following API:

    PrintDlgEx()

    So, try to use the new function and see if you still have the same
    issue.

    http://msdn2.microsoft.com/en-us/library/ms646942.aspx

    http://msdn2.microsoft.com/en-us/lib...aspx#print_dlg

    Kellie.



+ Reply to Thread