cancel
Showing results for 
Search instead for 
Did you mean: 

Using RDC with Visual C++ (COM, not .NET)

Former Member
0 Kudos

I am trying to use the sample code in the CR XI R2 documentation and am having trouble.

The machine I am developing on has CR IX installed in addition to CR XI.

I am using Visual C++ 6.

When I try the sample code, it crashes when I acess a NULL pointer m_Application.

m_Report = m_Application->OpenReport(ReportPath, dummy);

The pointer is NULL because the call m_Application.CreateInstance ("CrystalRuntime.Appplication.115") fails.

If I replace the m_Application.CreateInstance call with

m_Application.CreateInstance ("CrystalDesignRuntime.Application"); it does not crash and the report shows. But, how do I know if I am getting the CR XI version rather than the CR IX version?

I have had to vary the code from the example -- the #import failed because the craxdrt.dll was in a different place.

Any thoughts?

Al Beard

Update as of Mar 10, 2010

I tried adding the printing code as outlined in the sample code --

I had to change the m_Application.CreateInstance call's argument to "CrystalDesignRuntime.Application" as above.

However, it now crashes in the destructor of the application (MyRDCApp).

Edited by: Albert Beard on Mar 10, 2010 5:01 PM

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Albert,

Don't use 115 in the app reference, CR 11.0 and 11.5 does not know the difference, it's a known issue and will not be fixed.

Use: m_Application.CreateInstance ("CrystalRuntime.Appplication.11")

And change your #import to the location of craxdrt.dll as so:

#import "C:\Program Files\Business Objects\common\3.5\bin\craxdrt.dll" no_namespace rename("FindText","RptFindText")

Our runtime always goes to that location so it should not cause a problem. You could code it to test to make some other app is not pre-loading the wrong version of the RDC so your app is always using the right version.

You can get the version number this way:

bstrt version = m_Application->GetVersion();

CString a_output("version : ") ;

a_output += version;

MessageBox(a_output, "Info", MB_ICONASTERISK | MB_OK);

11.5 ( and 11.0 ) will return 2304.

Thank you

Don

Also, CR XI and CR XI R2 will work fine on the same PC as long as you specify the correct references you are using, you also need to update the CRViewer.dll to 11.5 in your form.

Edited by: Don Williams on Mar 10, 2010 10:50 AM

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks for your help.

Here's how I finally got it to work.

1) to preview -- the changes suggested earlier worked.

2) to print without crashing

I added a print button to the dialog box and moved the print code from the InitInstance() of the app to the OnPrint handler. I also simplified the code as most of it was a repeat of the code in the dialog's OnInitDialog() method.

3) I did not have to add the suggested code in the shut down of the app to spin waiting for the m_Viewer to go not busy.

All in all, the sample app in the Crystal Reports documentation was misleading.

So, this issue is closed.

-- Al Beard

Former Member
0 Kudos

the second half needs further work -- still a crash on exit.

0 Kudos

Hi Albert,

Add this on your closing methods:

while (!m_Viewer.GetIsBusy())

{

m_Report = NULL;

}

What the code does is close the report object only when the viewer is no longer busy.

Then it should not crash on exit.

Thank you

Don

Former Member
0 Kudos

Thanks Don & Ludek --

I can now preview the report using the sample code from Business Objects.

However, the second problem remains -- the App crashes with an access violation upon exit without printing the report.

The code in the App's InitInstance() is:

// a dummy variant

VariantInit (&dummy);

dummy.vt = VT_EMPTY;

HRESULT hr = S_OK;

// Specify the path to the report to be printed

bstrt ReportPath = "C:
Program Files
Business Objects
Crystal Reports 11.5
Samples
en
Reports
General Business
Inventory CrossTab.rpt";

variantt vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);

// Instantiate the IAppllication object

m_Application.CreateInstance ("CrystalRuntime.Application.11");

// Open the report using the OpenReport method

m_Report = m_Application->OpenReport (ReportPath, dummy);

// print the report to the printer

m_Report->PrintOut (dummy, dummy, dummy, dummy);

return FALSE;

Edited by: Albert Beard on Mar 10, 2010 11:52 PM

Edited by: Albert Beard on Mar 10, 2010 11:54 PM

Edited by: Albert Beard on Mar 10, 2010 11:57 PM (I hope I finally got the code snippet right.)

former_member183750
Active Contributor
0 Kudos

Having both CR XI r1 and CR XI r2 on the same computer is not a good idea. My recommendation would be to uninstall r1 and r2 and then reinstall r2 and go with that. No reason to keep r1 around...

Ludek