Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Loading Components

Table of Contents

Overview

Now that you have learned how to build the examples, lets go through the first example (loader-1) which shows you how to load components. This example shows the loading of the RGX Regular Expression Engine component, but all components are loaded the same way. So it serves as a good example for loading any P6R component library. The source of this example can be found in the examples/loader/loader-1 directory under you SKC installation directory.

In this example, we will initialize the p6Loader, create an instance of a p6IRegex interface, use the interface, and then release the ineterface and shutdown the loader.

Make sure to include the product's main include file (p6skc.h or p6xjr.h, etc. depending on which component libraries you are using) which will pull in all the includes needed. The C++ interface and definitions for all of P6R's component libraries are contained within the P6R namespace, so a using statement is added for convenience.

SKC uses [p6]COM interfaces, so the next step is to define the interface and component IDs we will be using. You will need to do this for every component interface that you use in a compilation unit.

p6Loader can take as and argument a data stream which is used to log debug and error messages. This is a simple implementation of a data stream that outputs everything to the console. This will be passed to loader when we initialize it.

The testRegex() function loads the regex interface using p6CreateInstance(), initializes the interface for use, and then compiles and executes a regular expression. If you are using a different component, it works the same way. Use p6CreateInstance(), passing it your components interface pointer, interface ID and component ID instead of those for the regular expression component.

Notice that the interface pointer is stored in the p6ComPtr<> smart pointer which will take care of calling release() on the interface when it goes out of scope. Using p6ComPtr<> is highly recommended for all interface pointers when possible. It makes coding easier and guards against resource leaks.

Here is the example's main(). Again we use a smart pointer to store the data stream interface pointer. First we create the data stream and then initialize the component loader by calling p6LoaderInitialize(). Once the loader is successfully initialized, you can create any number of interface instances by calling p6CreateInstance(). The "Loader API" reference is available from top nav bar.

Once the loader is successfully initialized, we call our regex function, then cleanup by calling p6CleanupLoader(). This will unload all shared libraries that have been loaded by the loader and free all the resources it was using. Take care to ensure that you have called release() on any component interfaced you were using (the p6ComPtr<> does this for you when it goes out of scope).