Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Crystal object in VC++

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
Hey guys, got another question for you. I've been trying to figgure out how to make and access a crystal object in my VC++ app. I've looked on the web, but I can't seem to find anything useful. If anyone has any info on this or can direct me to a webpage, I would be greatly appreciative. Thanks in advance.

Niky Williams
NTS Marketing
 
Hope this helps you.

1 Open Visual C++ 6.0 if it isn't already running.

2 From the File menu, select New. In the New dialog box select the MFC AppWizard (exe) from the Projects tab. Type in MyRDC for the Project Name and click OK.

3 From the first step in the wizard, select "Dialog based" and click the Finish button to accept the defaults for the MFC AppWizard and then click OK in the New Project Information dialog box.

4. When the wizard executes, a dialog appears in design mode. Right click on the dialog and choose "Insert ActiveX Control" from the popup-dialog. From the list of available controls, select "Crystal Report Viewer Control". Resize the control to the desired size. Rearrange the OK and Cancel buttons to their desired location.

5. Choose View | Class Wizard. Click on the Member Variables tab and ensure that the class name is CMyRDCDlg. Add a variable for the IDC_CRVIEWER1, you will be prompted whether or not to add the control to the project, click OK. Name the member variable for the viewer m_Viewer.

6. Add a reference to the RDC runtime object Model. Copy the file craxdrt.tlb from the C:\Program File\Seagate Software\Crystal Reports\Developr Files\include\ directory. From the File|Open menu select the MyRDCdlg.h file that was generated by the MFC App wizard and Click Open. Add the following line after the #include directives:

#import "craxdrt.tlb" no_namespace

7. Before you can invoke an RDC object, you must initialize OLE. From the File|Open menu, open the MyRDC.CPP file and add the following code before the message map:

struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_;

8. For optional Variant parameters declare a dummy variable as well as the member variables for the RDC's Application and Report objects in the MyRDCdlg.h header file after "Protected:" in the Implementation section.

IApplicationPtr m_Application;
IReportPtr m_Report;
VARIANT dummy;

9. Add the following constants in the declarations of the MyRDCdlg.CPP file:

// The constants needed to create the Application and Report Objects COM objects

const CLSID CLSID_Application = {0xb4741fd0,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
const IID IID_IApplication = {0x0bac5cf2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
const CLSID CLSID_ReportObjects = {0xb4741e60,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
const IID IID_IReportObjects = {0x0bac59b2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};

10. In the MyRDCdlg.CPP file. Add the following code to the CMyRDCDlg::OnInitDialog() method just before the return statement:

// A dummy variant
VariantInit (&dummy);
dummy.vt = VT_EMPTY;
HRESULT hr = S_OK;
IApplicationPtr m_Application = NULL;
IReportPtr m_Report = NULL;

// Specify the path to the report you want to print
_bstr_t ReportPath("c:\\Program Files\\Seagate Software\\Crystal Reports\\Samples\\Reports\\General Business\\Inventory.rpt");
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

// Instantiate the IApplication object
hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER , IID_IApplication, (void **) &m_Application);

//Open the Report using the OpenReport method
m_Report = m_Application->OpenReport(ReportPath, dummy);

//Print the Report to window
m_Viewer.SetReportSource(m_Report);
m_Viewer.ViewReport();

11. Finally, from the Build menu, select Rebuild All, then Execute. When the app runs, it opens the report and displays in the veiwer control on the application's dialog. Click OK or Cancel to dismiss the dialog and terminate the application.

That's all there is to it. There are hundreds of properties, methods, and events in the Report Designer Component object model that you can manipulate through your code to meet the demands of virtually any reporting requirement.


 
Ashorton,
Thanks for your reply, but I have finally figgure it out. I didn't quite go about it the way you did, but it works. :) Thanks again for your input! I do appreciate it!

Niky Williams
NTS Marketing, Inc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top