C++调用DotNet类库实现ISAPI Filter
- #include "stdafx.h"
- #include "mscoree.h"
- #include "stdio.h"
- #include "string.h"
- #include "httpfilt.h"
- //CLR宿主控制接口
- ICLRControl *clrcontrol=NULL;
- //CLR运行时宿主
- ICLRRuntimeHost * clr=NULL;
- //函数指针用于调用托管委托
- //函数指针用于调用DotNet类库中定义的函数
- DWORD (* FilterProc)(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType,VOID *pvNotification);//过滤器过滤事件调用的函数 参数一过滤器上下文(IIS) 事件类型 事件参数
- BOOL (* FilterVersion)(HTTP_FILTER_VERSION * pVer);//过滤器初始化时候调用pVer过滤器版本 程序中填充
- BOOL (* Terminate)(DWORD dwFlags);//卸载过滤器时候调用
- //以下三个方法定义又IIS调用的方法 然后转向调用上边定义的函数指针
- __declspec(dllexport) DWORD WINAPI HttpFilterProc(HTTP_FILTER_CONTEXT *pfc,DWORD NotificationType,VOID * pvNotification)
- {
- if(FilterProc!=NULL)
- return FilterProc(pfc,NotificationType,pvNotification);
- return 0;
- }
- __declspec(dllexport) BOOL WINAPI GetFilterVersion(HTTP_FILTER_VERSION * pVer)
- {
- if(FilterVersion==NULL)
- {
- Init();
- }
- if(FilterVersion!=NULL)
- {
- return FilterVersion(pVer);
- }
- return FALSE;
- }
- __declspec(dllexport) BOOL WINAPI TerminateFilter(DWORD