Citation :
Adding the RDC runtime library in Visual C++
1. Start a new project in Visual C++. Click the File menu and then click New.
Select MFC AppWiz and name the project. Click OK. Choose "Dialog
Based" in the first screen of the wizard and select "Finish"
2. In the application?s header file add the runtime library using the #import
keyword, for example:
#import ?craxdrt.dll? no_namespace;
3. In the application?s header file, use the IApplicationPtr class to declare an
Application object, for example:
IApplicationPtr pApplication;
4. In the class where you want use the Application object, create the
Application object, for example:
extern CMyApplicationApp theApp;
theApp.pApplication.CreateInstance("CrystalRuntime.Applicat
ion" );
Whereas the steps for Visual Basic are fairly intuitive, the same perhaps cannot
be said for the Visual C++ example given above. A few points bear explanation.
? The #import keyword exposes the various interfaces of Craxdrt.dll. You
should add the c:\program files\seagate software\report designer
component\ directory to the list of directories in Visual C++. To add the
directory, go the Tools menu, select Options and click the Directories tab.
? The no_namespace keyword indicates that you are not concerned with
creating a namespace for the set of interfaces you are importing.
? Craxdrt.dll exposes an interface called IApplication, however, the #import
keyword adds "Ptr" to the end of each interface to indicate that it has
wrapped the interfaces into smart pointers. Smart pointers do a bit of the
work for you, such as managing the life-cycle of the object created from the
interface and wrapping arguments into safe-arrays.
? Microsoft Foundation Classes (MFC) applications automatically create a
global application variable called theApp. Since you?ve declared RDC
interfaces in the application's header, they too are global and can be
accessed from the theApp variable. To do so, you need to declare theApp
in any class where we are using it using the extern keyword.
Although you have an Application object declared, you need to create the object
using the runtime. To do so, use the CreateInstance method of the object. The
method takes the programmatic identifier (ProgID) of the interface (for example,
CrystalRuntime.Application).
|