Example code for a Print-Only Link

The first step in accessing the Crystal Report Engine is to load it into memory. This can be done just before PEPrintReport is called, when a dialog box that allows printing opens, or even when your application first starts.

Once the Crystal Report Engine is open, PEPrintReport can be called as a result of some user action, such as clicking a button on screen, or some internal application procedure.

Finally, once you are finished with the Crystal Report Engine, close it by calling PECloseEngine. If you have several print jobs, do not close the Crystal Report Engine until all print jobs are finished. Opening and closing the Crystal Report Engine uses processor time and should only be performed when necessary.

The following C code demonstrates a possible message handler for an application that provides Print-Only Link functionality through a button in a dialog box. Use this code as an example of how to perform a Print-Only Link.

short result;
switch (message)
{
    case WM_INITDIALOG:
        if (!PEOpenEngine())
            ; // Handle error
        return TRUE;     case WM_DESTROY:
        PECloseEngine();
        return TRUE;     case WM_COMMAND:
        switch (wParam)
        {
            case IDC_PRINTBUTTON:
                result = PEPrintReport (
                    "boxoffic.rpt",
                    FALSE, TRUE,
                    "My Report",
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    hwndParent);
                if (result != 0)
                    return FALSE;
                return TRUE;
        }
        break;
}


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com