title | description | ms.date | ms.assetid |
---|---|---|---|
IHttpModuleFactory::GetHttpModule Method |
This article contains syntax, parameters, and return value for the IHttpModuleFactory::GetHttpModule method. |
10/07/2016 |
cc84322a-c40b-5296-1d42-20af0f7e4e95 |
Creates an instance of a CHttpModule class.
virtual HRESULT GetHttpModule(
OUT CHttpModule** ppModule,
IN IModuleAllocator* pAllocator
) = 0;
ppModule
[OUT] A dereferenced pointer to a CHttpModule class.
pAllocator
[IN] A pointer to an IModuleAllocator interface.
An HRESULT
. Possible values include, but are not limited to, those in the following table.
Value | Description |
---|---|
S_OK | Indicates that the operation was successful. |
Note
Because your module factory is required to provide a GetHttpModule
method, you can provide any status code for the return value as appropriate for your application. At the very least, your GetHttpModule
method should return S_OK to indicate a successful completion.
An IHttpModuleFactory interface must provide a GetHttpModule
method that creates an instance of your CHttpModule
class. When IIS calls your module's exported RegisterModule function, IIS will use module factory's GetHttpModule
method to create an instance of your CHttpModule
class.
The following code example demonstrates how to create a simple "Hello World" HTTP module. The module defines an exported RegisterModule
function that passes an instance of an IHttpModuleFactory
interface to the IHttpModuleRegistrationInfo::SetRequestNotifications method and registers for the RQ_BEGIN_REQUEST notification. IIS uses the GetHttpModule
method to create an instance of a CHttpModule
class and returns a success status. IIS also uses the Terminate method of the IHttpModuleFactory
interface to remove the factory from memory.
When a RQ_BEGIN_REQUEST
notification is triggered, IIS calls the module's CHttpModule::OnBeginRequest method to process the current request. OnBeginRequest
clears the response buffer and modifies the MIME type for the response. The method then creates a data chunk that contains a "Hello World" string and returns the string to a Web client. Finally, the module returns a status indicator that notifies IIS that all notifications are finished and then exits.
[!code-cppCHttpModuleHelloWorld#1]
Your module must export the RegisterModule
function. You can export this function by creating a module definition (.def) file for your project, or you can compile the module by using the /EXPORT:RegisterModule
switch. For more information, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code.
You can optionally compile the code by using the __stdcall (/Gz)
calling convention instead of explicitly declaring the calling convention for each function.
Type | Description |
---|---|
Client | - IIS 7.0 on [!INCLUDEwinvista] - IIS 7.5 on Windows 7 - IIS 8.0 on Windows 8 - IIS 10.0 on Windows 10 |
Server | - IIS 7.0 on [!INCLUDEwinsrv2008] - IIS 7.5 on Windows Server 2008 R2 - IIS 8.0 on Windows Server 2012 - IIS 8.5 on Windows Server 2012 R2 - IIS 10.0 on Windows Server 2016 |
Product | - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0 - [!INCLUDEiisexp75], [!INCLUDEiisexp80], [!INCLUDEiisexp100] |
Header | Httpserv.h |
CHttpModule Class
IHttpModuleFactory Interface
Designing Native-Code HTTP Modules
Walkthrough: Creating a Request-Level HTTP Module By Using Native Code