Help with managed C++/.NET/windows form viewer

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::DockStyle::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());
}
 
T

Tian Min Huang

Hi Dean,

Thanks for your post. Please refer to the following sample which
demonstrates opening a crystal report in the windows form viewer.
C++ .NET Windows Application - Accessing Subreport
http://support.crystaldecisions.com/communityCS/FilesAndUpdates/cppnet_win_s
ubreport_basic.exe.asp

The following article lists more .NET Crystal Report sample in C++ .NET.
Crystal Reports: Listing of .NET Sample Applications in C# and C++ .NET
http://support.crystaldecisions.com/communityCS/TechnicalPapers/apps_net.pdf

In addition, please be noted that "Microsoft supports setup and
installation for the Crystal Reports products that are included with Visual
Studio .NET. All other support is provided by Crystal Decisions."
(described in the KB article 317789 below). So I recommend you contact
Crystal Decisions to check whether there is any known issue on their side.

INFO: Licensing and Support for Crystal Reports for Visual Studio .NET
http://support.microsoft.com/?id=317789

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
T

Tian Min Huang

Hello Dean,

Did the information I posted last time help you resolve the problem?

I look forward to your response.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
D

Dean Poling

Tian,

Thanks for responding to the original message. The site you posted
did not help me much, but I did find a solution through other means.
I was attempting to open my class with Application::Run, but instead I
should have used the ShowDialog() method. Now my application works
great!

Thanks again,
Dean
 
T

Tian Min Huang

Hello Dean,

I am very glad to hear that you have resolved the problem! :)

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top