I have an MFC application with a crystal reports activeX control on a dialog. All works fine when displaying the report once, but when attempting to run the report a second time by closing and opening the dialog again, there is an assertion after entering parameters and closing that dialog.
I'm not sure how to go about debugging because I can't set any break points. The failing code is simply checking whether an hWnd is a window at the following code:
It begins opening the dialog then croaks.
Here is the code in my dialog class:
And to call the dialog I simply have a variable in the mainform class of that type and call like this:
I'm not sure how to go about debugging because I can't set any break points. The failing code is simply checking whether an hWnd is a window at the following code:
Code:
[COLOR=green]// afxwin2.inl[/color]
_AFXWIN_INLINE void CWnd::UpdateWindow()
{ ASSERT(::IsWindow(m_hWnd)); ::UpdateWindow(m_hWnd); }
It begins opening the dialog then croaks.
Here is the code in my dialog class:
Code:
[COLOR=green]// ReportViewer.cpp : implementation file
//[/color]
[COLOR=red]
#include "stdafx.h"
#include "Fuel_Refund_MFC.h"
#include "ReportViewer.h"[/color]
[COLOR=green]// CReportViewer dialog[/color]
IMPLEMENT_DYNAMIC(CReportViewer, CExtResizableDialog)
CReportViewer::CReportViewer(CWnd* pParent /*=NULL*/)
: CExtResizableDialog(CReportViewer::IDD, pParent)
{
[COLOR=blue]try[/color]
{
[COLOR=green]// Create instance of Application object[/color]
m_Application.CreateInstance([COLOR=red]"CrystalDesignRunTime.Application.10"[/color]);
}
[COLOR=blue]catch[/color](_com_error& e)
{
[COLOR=green]// if errors occur, handle and display errors[/color]
HandleError(e);
}
[COLOR=green]// initialize the m_Report variable to NULL[/color]
m_Report = NULL;
}
CReportViewer::~CReportViewer()
{
}
void CReportViewer::DoDataExchange(CDataExchange* pDX)
{
CExtResizableDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_ACTIVEXREPORTVIEWER1, pCtrlReportViewer);
}
BEGIN_MESSAGE_MAP(CReportViewer, CDialog)
ON_WM_SIZE()
END_MESSAGE_MAP()
[COLOR=green]// CReportViewer message handlers[/color]
BOOL CReportViewer::OnInitDialog()
{
CExtResizableDialog::OnInitDialog();
[COLOR=green]// TODO: Add extra initialization here[/color]
HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
SetIcon(hIcon, FALSE);
[COLOR=green]/*pCtrlReportViewer.ShowWindow(SW_HIDE);*/[/color]
InitReport();
[COLOR=green]// Add anchor to control[/color]
AddAnchor( IDC_ACTIVEXREPORTVIEWER1, __RDA_LT, __RDA_RB);
[COLOR=green]//return TRUE; // return TRUE unless you set the focus to a control[/color]
return FALSE; [COLOR=green]// EXCEPTION: OCX Property Pages should return FALSE[/color]
}
void CReportViewer::InitReport()
{
[COLOR=green]// A Dummy variant[/color]
TRY
{
VariantInit(&dummy);
dummy.vt = VT_EMPTY;
[COLOR=green]/*CLSID CLSID_Application;
CLSIDFromProgID(L"CrystalDesignRunTime.Application.10", &CLSID_Application);
HRESULT hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER ,
__uuidof(IApplication), (void **) &m_Application);
ASSERT(SUCCEEDED(hr));*/[/color]
_bstr_t FileName( [COLOR=red]"Refund.rpt"[/color] );
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
[COLOR=green]// Open the report using the OpenReport method[/color]
m_Report = m_Application->OpenReport(FileName, dummy);
m_Report->DiscardSavedData();
pCtrlReportViewer.SetReportSource(m_Report);
pCtrlReportViewer.Zoom(1);
pCtrlReportViewer.ViewReport();
[COLOR=green]//pCtrlReportViewer.ShowWindow(SW_SHOW);[/color]
}
CATCH_ALL(e)
{
AfxMessageBox(_T([COLOR=red]"An unhandled exception has occurred."[/color]));
}
END_CATCH_ALL
}
void CReportViewer::PostNcDestroy()
{
[COLOR=green]// TODO: Add your specialized code here and/or call the base class[/color]
m_Report.Release();
m_Report = NULL;
m_Application.Release();
m_Application = NULL;
CExtResizableDialog::PostNcDestroy();
}
[COLOR=green]// A utility COM error handler[/color]
void CReportViewer::HandleError(_com_error &e)
{
IErrorInfo* pErrorInfo = e.ErrorInfo();
HRESULT hr = e.Error();
if (pErrorInfo)
{
BSTR bsDesc = NULL;
pErrorInfo->GetDescription(&bsDesc);
_bstr_t sDesc(bsDesc,false);
::MessageBox(0,sDesc.operator LPCTSTR(), _T([COLOR=red]""[/color]),MB_OK);
pErrorInfo->Release();
}
}
void CReportViewer::OnSize(UINT nType, int cx, int cy)
{
CExtResizableDialog::OnSize(nType, cx, cy);
[COLOR=green]// TODO: Add your message handler code here[/color]
if (!::IsWindow(pCtrlReportViewer.m_hWnd))
{
return;
}
}
And to call the dialog I simply have a variable in the mainform class of that type and call like this:
Code:
CReportViewer Dlg;
Dlg.DoModal();