返回导致事件的动态函数调用的名称。
语法
virtual PCWSTR GetFunctionName(
VOID
) const = 0;
参数
此方法不采用参数。
返回值
指向常量以 null 结尾的 Unicode 字符串的指针,该字符串包含导致事件的函数的名称。
备注
注册GL_RSCA_QUERY事件的 CGlobalModule 派生类接收 IGlobalRscaQueryProvider 指针作为 CGlobalModule::OnGlobalRSCAQueryvirtual
方法上的参数。 然后,可以通过在指针上IGlobalRSCAQueryProvider
调用 GetFunctionName
方法来检索函数名称。
方法的 GetFunctionName
返回值取决于实现。 应将以下信息用作指南,但并非所有情况都正确:
调用 IRSCA_WorkerProcess::EnumerateAppDomains 和 IRSCA_AppDomain::Unload 方法时,IProtocolManager、IPmCustomActions、IPmHealthAndIdleMonitor 和 IPmListenerChannelManager 接口的默认实现器会引发事件。 这些方法分别映射到PMH_App_Domain_Enum_V1和PMH_App_Domain_Unload_V1值,这些值在调用
GetFunctionName
时返回。 调用 GetFunctionParameters 方法时,此函数的参数又返回。当
IGlobalRSCAQueryProvider
引发 IRSCA_AppDomain事件之 一时,实现者接收函数名称和函数参数值作为字符串,并且实现者持有对这些字符串的引用。 如果字符串为 NULL,GetFunctionName
则返回空字符串。 否则,GetFunctionName
返回指向此共享字符串的指针。
实现者须知
IGlobalRSCAQueryProvider
实施者负责使用此数据进行内存管理;因此,IGlobalRSCAQueryProvider
使用动态内存分配的实现程序必须在不再需要指针时释放或调用delete
PCWSTR
指针。
对调用者的说明
IGlobalRSCAQueryProvider
实施者负责使用此数据进行内存管理;因此,当不再需要此数据时, IGlobalRSCAQueryProvider
客户端不得释放或调用 delete
返回 PCWSTR
的指针。 此外,客户端不得将此数据强制转换为不是 const
的指针或更改此 PCWSTR
引用的内存的状态,因为将引发访问冲突,或者数据将变为无效。
示例
下面的代码示例演示如何创建一个全局模块,该模块侦听GL_RSCA_QUERY事件,然后将函数名称信息写入事件查看器。
注意
IIS 7 在事件查看器中生成大量事件。 若要避免生产环境中的日志溢出错误,通常应避免将缓存信息写入事件日志。 出于演示目的,此代码示例仅在调试模式下向事件查看器写入一个条目。
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <tchar.h>
#include <httpserv.h>
#include <string>
using namespace std;
// The CConvert class mirrors the Convert class that is
// defined in the .NET Framework. It converts primitives
// and other data types to wstring types.
class CConvert
{
public:
// The ToByteString converts a double-byte
// character string to a single-byte string.
// str: the double-byte string to convert.
// return: a single-byte string copied from str.
static string ToByteString(const wstring& str)
{
// Get the length of the
// double-byte string.
size_t length = str.length();
// Create a temporary char pointer.
char* byteChar = new char[length+1];
byteChar[0] = '\0';
// Copy the double-byte character string
// into the single-byte string.
size_t charsReturned = 0;
wcstombs_s(&charsReturned, byteChar,
length+1, str.c_str(), length+1);
// Create a string to return.
string retString = byteChar;
// Delete the temporary string and
// set that string to NULL.
delete[] byteChar;
byteChar = NULL;
// Return the single-byte string.
return retString;
}
};
// The CEventWriter class writes XML
// documents and strings to the event log.
class CEventWriter
{
public:
// Creates the CEventWriter class.
// name: the name of the
// event log to open.
CEventWriter(const wstring& name)
{
#ifdef UNICODE
m_eventLog = RegisterEventSource(NULL, name.c_str());
#else
string multiName = CConvert::ToByteString(name);
m_eventLog = RegisterEventSource(NULL, multiName.c_str());
#endif
}
// Creates the destructor for the
// CEventWriter class. This destructor
// closes the HANDLE to the event
// log if that HANDLE is open.
virtual ~CEventWriter()
{
// If the HANDLE to the event
// log is open, close it.
if (NULL != m_eventLog)
{
// Deregister the event log HANDLE.
DeregisterEventSource(m_eventLog);
// Set the HANDLE to NULL.
m_eventLog = NULL;
}
}
// The ReportInfo method writes
// a wstring to the event log.
// info: the wstring to write.
// return: true if the event log is written.
BOOL ReportInfo(const wstring& info)
{
return ReportEvent(EVENTLOG_INFORMATION_TYPE, info);
}
protected:
// The ReportEvent method accepts an event type
// and a wstring, and attempts to write that
// event to the event log.
// type: the type of the event.
// data: the wstring to write to the event log.
// return: true if the event log is written;
// otherwise, false.
BOOL ReportEvent(WORD type, const wstring& data)
{
// If the m_eventLog HANDLE
// is NULL, return false.
if (NULL == m_eventLog)
{
return FALSE;
}
#ifndef _DEBUG
// If the current build is not debug,
// return so the event log is not written.
return TRUE;
#endif
#ifdef UNICODE
// The unicode version of the ReportEvent
// method requires double-byte strings.
PCWSTR arr[1];
arr[0] = data.c_str();
return ::ReportEvent(m_eventLog,
type,
0, 0, NULL, 1,
0, arr, (void*)arr);
#else
// The non-unicode version of the ReportEvent
// method requires single-byte strings.
string multiByte =
CConvert::ToByteString(data);
LPCSTR arr[1];
arr[0] = multiByte.c_str();
return ::ReportEvent(m_eventLog,
type,
0, 0, NULL, 1,
0, arr, (void*)arr);
#endif
}
private:
// Specify the HANDLE to the
// event log for writing.
HANDLE m_eventLog;
};
// The CRSCAGlobalModule class creates the CGlobalModule
// class and registers for GL_RSCA_QUERY and events.
class CRSCAGlobalModule : public CGlobalModule
{
public:
// Creates the destructor for the
// CGlobalCacheModule class.
virtual ~CRSCAGlobalModule()
{
}
// The RegisterGlobalModule method creates and registers
// a new CRSCAGlobalModule for GL_RSCA_QUERY events.
// dwServerVersion: the current server version.
// pModuleInfo: the current IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: E_INVALIDARG if the IHttpServer pointer
// is NULL; ERROR_NOT_ENOUGH_MEMORY if the heap is out of
// memory; otherwise, the value from the call to the
// SetGlobalNotifications method on the pModuleInfo pointer.
static HRESULT RegisterGlobalModule
(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// The pGlobalInfo parmeter must be
// non-NULL because the constructor
// for the CGlobalCacheModule class
// requires a non-NULL pointer to a
// valid IHttpServer pointer.
if (NULL == pGlobalInfo)
{
return E_INVALIDARG;
}
// Create a new CGlobalCacheModule pointer.
CRSCAGlobalModule* rscaModule =
new CRSCAGlobalModule();
// Return an out-of-memory error
// if the traceModule is NULL
// after the call to the new operator.
if (NULL == rscaModule)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
// Attempt to set global notification
// for GL_RSCA_QUERY events by using
// the rscaModule as a listener.
HRESULT hr = pModuleInfo->SetGlobalNotifications
(rscaModule, GL_RSCA_QUERY);
// Return the HRESULT from the call to
// the SetGlobalNotifications method.
return hr;
}
// The OnGlobalRSCAQuery method is the event
// handler method for the GL_RSCA_QUERY event.
// pProvider: the IGlobalRSCAQueryProvider pointer.
// return: GL_NOTIFICATION_CONTINUE.
virtual GLOBAL_NOTIFICATION_STATUS OnGlobalRSCAQuery
(
IN IGlobalRSCAQueryProvider* pProvider
)
{
// Return GL_NOTIFICATION_CONTINUE if the
// IGlobalRSCAQueryProvider pointer is NULL.
if (NULL == pProvider)
{
return GL_NOTIFICATION_CONTINUE;
}
// Get the name of the function from
// the IGlobalRSCAQueryProvider pointer.
wstring functionName =
pProvider->GetFunctionName();
// Write the function name
// information to the event writer.
m_eventWriter.ReportInfo
(L"Function Name: " + functionName);
// Return GL_NOTIFICATION_CONTINUE so
// other listeners will receive this event.
return GL_NOTIFICATION_CONTINUE;
}
// The Terminate method is a pure virtual
// method that all non-abstract CGlobalModule
// classes must implement. Calls delete on this.
virtual VOID Terminate(VOID)
{
delete this;
}
protected:
// Creates the CRSCAGlobalModule class.
// Initializes the CEventWriter to write
// to the event log using the IISADMIN key.
CRSCAGlobalModule() : m_eventWriter(L"IISADMIN")
{
}
private:
// Specify the CEventWriter writer.
CEventWriter m_eventWriter;
};
// The RegisterModule method is the
// main entry point for the DLL.
// dwServerVersion: the current server version.
// pModuleInfo: the current
// IHttpModuleRegistrationInfo pointer.
// pGlobalInfo: the current IHttpServer pointer.
// return: the value returned by calling the
// CRSCAGlobalModule::RegisterGlobalModule
// method.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
)
{
// Call the static method for initialization.
return CRSCAGlobalModule::RegisterGlobalModule
(dwServerVersion,
pModuleInfo,
pGlobalInfo);
}
有关如何创建和部署本机 DLL 模块的详细信息,请参阅 演练:使用本机代码创建 Request-Level HTTP 模块。
上述代码将两个新事件写入事件查看器的应用程序日志,其中 Data box 包含类似于以下内容的字符串:
Function Name: PMH_App_Domain_Enum_V1
可以选择使用 __stdcall (/Gz)
调用约定编译代码,而不是为每个函数显式声明调用约定。
要求
类型 | 说明 |
---|---|
客户端 | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10 上的 IIS 10.0 |
服务器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016 上的 IIS 10.0 |
产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 - IIS Express 7.5、IIS Express 8.0、IIS Express 10.0 |
Header | Httpserv.h |