Article ID: 185518
Article Last Modified on 6/22/2006
class CMyAppExtension : public CHttpServer
{
public:
// Code generated by the ClassWizard.
// Simply include the method in the public section of the code
// generated by the ClassWizard making certain not to alter
// anything else.
virtual DWORD HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB);
};
DWORD CMyAppExtension::HttpExtensionProc( EXTENSION_CONTROL_BLOCK
*pECB)
{
// The result of the base class's (CHttpServer) HttpExtensionProc()
// must be checked. If it's successful, you will need to return a
// HSE_STATUS_PENDING. This is so that IIS will not shutdown the
// connection and not destroy the ECB.
// If the result of the base class is not successful, you should
// simply propagate the error message up to IIS.
DWORD dwResult = CHttpServer::HttpExtensionProc(pECB);
if(dwResult == HSE_STATUS_SUCCESS)
return HSE_STATUS_PENDING;
else
return dwResult;
}
void CMyAppExtension::Default(CHttpServerContext* pCtxt)
{
// Setting the m_bSendHeaders variable to FALSE will prevent
// IIS from sending headers; this must be handled by your
// thread.
pCtxt->m_bSendHeaders = FALSE;
// Spawn thread...you must use AfxBeginThread since this is an MFC
// based extension.
AfxBeginThread((AFX_THREADPROC)MyThreadProc,
(LPVOID)(pCtxt->m_pECB));
}
If you are using some other function that takes several parameters, you
should create your own class/struct to encapsulate the ECB pointer and
your parameters and pass a pointer to that class to the thread process
(just make sure you clean up your class/struct).
UINT MyThreadProc(LPVOID pvParam)
{
EXTENSION_CONTROL_BLOCK *pECB = (EXTENSION_CONTROL_BLOCK*)pvParam;
// Do some processing here...
// To send custom headers, remember to set the m_bSendHeaders to
// FALSE in the CHttpServerContext from the method that spawned
// this thread and use the ServerSupportFunction().
// Write data to the client...
// pECB->WriteClient(...);
// Before returning from the thread routine, you must send the
// HSE_REQ_DONE_WITH_SESSION flag so IIS can clean up the session.
pECB->ServerSupportFunction(pECB->ConnID,
HSE_REQ_DONE_WITH_SESSION,
NULL, NULL, 0);
return 0;
}
119591 How to Obtain Microsoft Support Files from Online Services
197728 Creating a Thread Pool for MFC-Based ISAPI Extensions
Additional query words: kbDSupport kbdsi
Keywords: kbdownload kbfilter kbhowto kbhttp KB185518