Debug Assertion Failded when I call printing function again

  assertion, c++, mfc, printing, windows-ce

I created application in MFC C++ Framework which set the properties of ECG signal and next print it.
Application is for WinCE 2013 OS.
Below is dialog box of application:

SignalConfiguration DialogBox
When I push "Print" button the program work correctly and print ECG signal with set properties.
Unfortunatelly while another calling this function I get this failure:
Debug Assertion Failed

Configuration of printer:

    BOOL Druk::Configuration()
{
    TCHAR DriverName[256];
    TCHAR DeviceName[256];
    TCHAR OutputName[256];
    ZeroMemory(&psd, sizeof(psd));
    psd.lStructSize = sizeof(psd); // psd is member of PAGESETUPDLG structure
    //psd.hwndOwner = hWnd;
    psd.hDevMode = NULL; // Don't forget to free or store hDevMode.
    psd.hDevNames = NULL; // Don't forget to free or store hDevNames.
    psd.Flags = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS;
    psd.rtMargin.top = 100;
    psd.rtMargin.left = 100;
    psd.rtMargin.right = 100;
    psd.rtMargin.bottom = 500; 
    psd.rtMinMargin.bottom = 500;
    lf_vertic.lfHeight = 30; // is member of LOGFONT structure
    lf_vertic.lfWidth = 0;
    //lf.lfOrientation = 2700;
    lf_vertic.lfEscapement = 0;
    lf_vertic.lfUnderline = FALSE;
    lf_vertic.lfWeight = FW_BOLD;
    lf_horizont.lfHeight = 30;
    lf_horizont.lfWidth = 0;
    //lf.lfOrientation = 2700;
    lf_horizont.lfEscapement = 2700;
    lf_horizont.lfUnderline = FALSE;
    lf_horizont.lfWeight = FW_BOLD;
    hFontVertic = CreateFontIndirect(&lf_vertic);
    hFontHorizont = CreateFontIndirect(&lf_horizont);
    DWORD error;
    if (PageSetupDlg(&psd) == TRUE)
    {
        memcpy(&dm, (DEVMODE *)(psd.hDevMode), sizeof(DEVMODE));
        lstrcpy(DriverName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDriverOffset)));
        lstrcpy(DeviceName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDeviceOffset)));
        lstrcpy(OutputName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wOutputOffset)));
        //hDC = CreateDC(DriverName, DeviceName, OutputName, &dm); // Wersja dla WinAPI do usunięcia w wersji finalnej
        hDC.CreateDC(DriverName, DeviceName, OutputName, NULL);
    }
    //error = CommDlgExtendedError();
    return TRUE;

}

Sample of printing function

    BOOL Druk::StartPrint()
{
    Configuration();
    StartDoc(hDC, NULL);
    //StartPage(hDC);
    return TRUE;
}
void Druk::DrawScaleVertic(int x, int y)
{
    //HPEN Pioro, Pudelko; // pozostałość po WinAPI do usunięcia
    CPen scale_pen;

    scale_pen.CreatePen(PS_SOLID, 2, NULL);
    //SelectObject(hDC, Pioro); // pozostałość po WinAPI do usunięcia w finalnej wersji
    hDC.SelectObject(scale_pen);
    hDC.MoveTo(x, y);
    //MoveToEx(hDC,x, y,NULL); Pozostałość po WinAPI do usunuięcia w finalnej wersji
    hDC.LineTo(x, y - MILIMETER*amplitude);
    //LineTo(hDC, x, y - MILIMETER*amplitude); Pozostałość po WinAPI do usunuięcia w finalnej wersji
    hDC.LineTo(x + 40, y - MILIMETER*amplitude);
    //LineTo(hDC, x + 40, y - MILIMETER*amplitude); Pozostałość po WinAPI do usunuięcia w finalnej wersji
    hDC.LineTo(x + 40, y);
    //LineTo(hDC, x + 40, y);
    DeleteObject(scale_pen);
}
void Druk::DrawExaminationTextBox_Horizont(int start_x, int start_y,int stop_y)
{
    MoveToEx(hDC,start_x, start_y,NULL);
    LineTo(hDC,start_x - 80, start_y);
    LineTo(hDC,start_x - 80, stop_y);
    LineTo(hDC,start_x, stop_y);
    LineTo(hDC,start_x, start_y);
}
BOOL Druk::DrawGrid(int start_x, int start_y, int limit_x, int limit_y, int width)
{
    CPen grid_pen;

    //HPEN pen; wersja dla WinAPI do usunięcia w finalnej wersji
    COLORREF linecol;
    grid_pen.CreatePen(PS_SOLID, width, NULL);
    //pen = CPen::CreatePen(PS_SOLID, width, NULL); wersja dla WinAPI do usunięcia w finalnej wersji
    hDC.SelectObject(grid_pen);
    //SelectObject(hDC, pen); wersja dla WinAPI do usunięcia w finalnej wersji
    for (float i = start_y; i < limit_y; i += 5 * MILIMETER)
    {
        MoveToEx(hDC, start_x, i, NULL);
        LineTo(hDC, limit_x, i);
    }
    for (float j = start_x; j < limit_x; j += 5 * MILIMETER)
    {
        MoveToEx(hDC, j, start_y, NULL);
        LineTo(hDC, j, limit_y);

    }
    for (float i = start_x; i < limit_x; i += MILIMETER)
    {
        for (float j = start_y; j < limit_y; j += MILIMETER)
        {
            MoveToEx(hDC, i, j, NULL);
            LineTo(hDC, i + 1, j);
        }
    }

    return TRUE;
}
void Druk::rysujEKG_Vertical(short * pointer, int start_x, int limit_x, int offset)
{

    //HPEN CzerwonePioro, Pudelko;// wersja dla WinAPI do usunięcia w ostatecznej wersji
    CPen CzerwonePioro;
    CPen Pudelko;
    CzerwonePioro.CreatePen(PS_SOLID, 2, NULL);
    int i = 1;
    int j = 1;
    do
    {
        if ((offset + SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*pointer) > FIELD_LIMIT_HIGH_VERTICAL) || (offset + SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*(pointer + 1)) > FIELD_LIMIT_HIGH_VERTICAL) || (offset + SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*(pointer)) < FIELD_LIMIT_LOW_VERTICAL) || (offset + SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*(pointer + 1))< FIELD_LIMIT_LOW_VERTICAL))
        {
            pointer++;
            i++;
            j++;
        }
        else
        {
            int x, y1, y2;
            //Pudelko = (HPEN)hDC.SelectObject(hDC, CzerwonePioro);
            hDC.SelectObject(CzerwonePioro);
            //float a = (MILIMETER / frequency)*sig_speed*j
            MoveToEx(hDC, start_x + (MILIMETER / frequency)*sig_speed*j, offset - SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*pointer), NULL);
            pointer++;
            LineTo(hDC, start_x + ((MILIMETER / frequency)*sig_speed*j + 1), offset - SIGNAL_AMPLITUDE_COEFICIENT*amplitude*(*pointer));
            j += 1;
            i += 1;
        }
    } while (i < new_sign_len);
    //druk.setSignalLength(WYDRUK_I_SIG_LEN - new_sign_len - startSample);
}

What is a way to fix this error?

Source: Windows Questions C++

LEAVE A COMMENT