This example demonstrates how to create and use a component that uses the ASP built-in objects. It provides a sample context framework that can be used to simplify gaining access to the objects, and it expands on the component demonstrated in the Simple C++ Component sample.
This sample implements the dual COM interface IPower. In addition to implementing the three methods contained in the sample Simple C++ Component (get_myProperty, put_myProperty, and myMethod), this sample implements two other methods.
The first additional method, get_myPowerProperty, uses the CContext class contained in the files CONTEXT.CPP and CONTEXT.H. This special class provides a wrapper around the COM interfaces exposed by ASP's built-in objects. get_myPowerProperty gains a pointer to the IRequest interface, and uses the interface's get_ServerVariables method to gain access to the server variables associated with the active request context. By using the IRequestDictionary interface's get_Item method, the method retrieves the SCRIPT_NAME server variable, and returns the value to the caller.
Note By not providing a corresponding put_myPowerProperty method, this sample implicitly declares that myPowerProperty is read-only.
The second additional method in the component's IPower interface, myPowerMethod, also uses the CContext class to gain access to the server variables associated with the active request context, as well as the IResponse interface. When this method is invoked, the server variable HTTP_USER_AGENT is retrieved from the calling context, and the component will use the Response.Write method to pass on a compliment, or a few words of advice, directly to the client browser.
This project is available in the ...\components\c++\intermediate subdirectory of the IIS samples directory.