D
Dean Poling
Hello, all...
I am attempting to write a managed c++ dll that will open a crystal
report in the windows form viewer. For various reasons, I need to be
able to write this in C++ w/MFC as opposed to C#. The code below is
called when the user doubleclicks an entry in a tree control. The
first time the user doubleclicks this entry, the code below works
wonderfully. However, the second time the user doubleclicks, the
windows form viewer flashes the report on the screen for a split
second, then disappears. It appears that the code below works fine on
the odd-numbered invocations, but the even numbered invocations act as
described (i.e. the code below works every other attempt, but on the
attempts when it doesn't work the viewer flashes on the screen for a
split second). Also, it seems like the destructor never gets called
(perhaps this is a symptom of the problem???) I have never worked
much with managed code or .NET, so any advice or help would be
appreciated.
Thanks,
Dean
__gc class ViewForm : public System::Windows::Forms::Form
{
private:
CrystalDecisions::Windows::Forms::CrystalReportViewer
*crystalReportViewer1;
ReportDocument *crReportDocument;
public:
ViewForm()
{
MessageBox(NULL, "CONSTRUCTOR", "TEST", MB_OK);
InitForm() ;
}
~ViewForm()
{
MessageBox(NULL, "DESTRUCTOR", "TEST", MB_OK);
Dispose() ;
}
void InitForm()
{
#pragma push_macro("new")
#undef new
crystalReportViewer1 = new
CrystalDecisions::Windows::Forms::CrystalReportViewer();
#pragma pop_macro("new")
crystalReportViewer1->ActiveViewIndex = -1;
crystalReportViewer1->Dock =
System::Windows::Forms:
ockStyle::Fill;
crystalReportViewer1->Name = "crystalReportViewer1";
crystalReportViewer1->TabIndex = 0;
Controls->Add (crystalReportViewer1);
WindowState =
System::Windows::Forms::FormWindowState::Maximized;
Load += new System::EventHandler (this, ViewForm_Load);
}
void ViewForm_Load(System::Object* sender, System::EventArgs* e)
{
#pragma push_macro("new")
#undef new
crReportDocument = new ReportDocument();
#pragma pop_macro("new")
crReportDocument->Load("C:\\Reports\\test.rpt");
crystalReportViewer1->ReportSource = crReportDocument;
}
};
extern void EXPORT testReportViewer()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
Application::Run(new ViewForm());
}
I am attempting to write a managed c++ dll that will open a crystal
report in the windows form viewer. For various reasons, I need to be
able to write this in C++ w/MFC as opposed to C#. The code below is
called when the user doubleclicks an entry in a tree control. The
first time the user doubleclicks this entry, the code below works
wonderfully. However, the second time the user doubleclicks, the
windows form viewer flashes the report on the screen for a split
second, then disappears. It appears that the code below works fine on
the odd-numbered invocations, but the even numbered invocations act as
described (i.e. the code below works every other attempt, but on the
attempts when it doesn't work the viewer flashes on the screen for a
split second). Also, it seems like the destructor never gets called
(perhaps this is a symptom of the problem???) I have never worked
much with managed code or .NET, so any advice or help would be
appreciated.
Thanks,
Dean
__gc class ViewForm : public System::Windows::Forms::Form
{
private:
CrystalDecisions::Windows::Forms::CrystalReportViewer
*crystalReportViewer1;
ReportDocument *crReportDocument;
public:
ViewForm()
{
MessageBox(NULL, "CONSTRUCTOR", "TEST", MB_OK);
InitForm() ;
}
~ViewForm()
{
MessageBox(NULL, "DESTRUCTOR", "TEST", MB_OK);
Dispose() ;
}
void InitForm()
{
#pragma push_macro("new")
#undef new
crystalReportViewer1 = new
CrystalDecisions::Windows::Forms::CrystalReportViewer();
#pragma pop_macro("new")
crystalReportViewer1->ActiveViewIndex = -1;
crystalReportViewer1->Dock =
System::Windows::Forms:

crystalReportViewer1->Name = "crystalReportViewer1";
crystalReportViewer1->TabIndex = 0;
Controls->Add (crystalReportViewer1);
WindowState =
System::Windows::Forms::FormWindowState::Maximized;
Load += new System::EventHandler (this, ViewForm_Load);
}
void ViewForm_Load(System::Object* sender, System::EventArgs* e)
{
#pragma push_macro("new")
#undef new
crReportDocument = new ReportDocument();
#pragma pop_macro("new")
crReportDocument->Load("C:\\Reports\\test.rpt");
crystalReportViewer1->ReportSource = crReportDocument;
}
};
extern void EXPORT testReportViewer()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
Application::Run(new ViewForm());
}