⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 responseobject.cpp

📁 vc++6.0开发网络典型应用实例导航 1. 本光盘提供了本书中所有的实例源程序文件。 2. 附录文件夹下是Winsock 函数参考以及错误码列表
💻 CPP
字号:
/********************************************************************/
/*																	*/
/*  ResponseObject.cpp												*/
/*																	*/
/*  Implementation of the CResponseObject class.					*/
/*																	*/
/*  Programmed by Pablo van der Meer								*/
/*	This code is stolen from: http://www.pablovandermeer.nl			*/
/*																	*/
/*  Last updated: July 4, 2003										*/
/*																	*/
/********************************************************************/


#include "stdafx.h"
#include "ResponseObject.h"
#include "CookieCollection.h"
#include "Cookie.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CResponseObject, CCmdTarget)

/********************************************************************/
/*																	*/
/* Function name : CResponseObject::CResponseObject					*/
/* Description   : Constructor										*/
/*																	*/
/********************************************************************/
CResponseObject::CResponseObject()
{
	EnableAutomation();
	m_strResponseBuffer.Empty();
	m_bEnabled = TRUE;
	m_bBuffer = TRUE;
}


/********************************************************************/
/*																	*/
/* Function name : CResponseObject::~CResponseObject				*/
/* Description   : Destructor										*/
/*																	*/
/********************************************************************/
CResponseObject::~CResponseObject()
{
}


/********************************************************************/
/*																	*/
/* Function name : OnFinalRelease									*/
/* Description   :													*/
/*																	*/
/********************************************************************/
void CResponseObject::OnFinalRelease()
{
	// When the last reference for an automation object is released
	// OnFinalRelease is called.  The base class will automatically
	// deletes the object.  Add additional cleanup required for your
	// object before calling the base class.

	CCmdTarget::OnFinalRelease();
}

BEGIN_MESSAGE_MAP(CResponseObject, CCmdTarget)
	//{{AFX_MSG_MAP(CResponseObject)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CResponseObject, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CResponseObject)
	DISP_PROPERTY_EX(CResponseObject, "Cookies", GetCookies, SetNotSupported, VT_DISPATCH)
	DISP_PROPERTY_EX(CResponseObject, "Buffer", GetBuffer, SetBuffer, VT_BOOL)
	DISP_FUNCTION(CResponseObject, "End", End, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CResponseObject, "Clear", Clear, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CResponseObject, "Write", Write, VT_EMPTY, VTS_BSTR)
	DISP_FUNCTION(CResponseObject, "Redirect", Redirect, VT_EMPTY, VTS_BSTR)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

//	DISP_FUNCTION(CResponseObject, "Cookies", Cookies, VT_DISPATCH, VTS_NONE)

// Note: we add support for IID_IResponseObject to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {149534DD-4630-4BDF-BDC2-498B9942E31A}
static const IID IID_IResponseObject =
{ 0x149534dd, 0x4630, 0x4bdf, { 0xbd, 0xc2, 0x49, 0x8b, 0x99, 0x42, 0xe3, 0x1a } };

BEGIN_INTERFACE_MAP(CResponseObject, CCmdTarget)
	INTERFACE_PART(CResponseObject, IID_IResponseObject, Dispatch)
END_INTERFACE_MAP()


/********************************************************************/
/*																	*/
/* Function name : Clear											*/
/* Description   : Erases any buffered HTML output.					*/
/*																	*/
/********************************************************************/
void CResponseObject::Clear() 
{
	// Re-enable processing
	m_bEnabled = TRUE;
	m_strResponseBuffer.Empty(); 
}


/********************************************************************/
/*																	*/
/* Function name : End												*/
/* Description   : Causes the server to stop processing a script	*/
/*				   and return the current response.					*/
/*																	*/
/********************************************************************/
void CResponseObject::End() 
{
	m_bEnabled = FALSE;
}


/********************************************************************/
/*																	*/
/* Function name : Write											*/
/* Description   : Writes a variant to the HTTP output.				*/
/*																	*/
/********************************************************************/
void CResponseObject::Write(LPCTSTR lpszText) 
{
	if (m_bEnabled)
		m_strResponseBuffer += lpszText;
}


/********************************************************************/
/*																	*/
/* Function name : Redirect											*/
/* Description   : Redirect.										*/
/*																	*/
/********************************************************************/
void CResponseObject::Redirect(LPCTSTR lpszURL) 
{
	m_strRedirectURL = lpszURL;
}


/********************************************************************/
/*																	*/
/* Function name : Cookies											*/
/* Description   : Return Cookies IDispatch pointer 				*/
/*																	*/
/********************************************************************/
LPDISPATCH CResponseObject::GetCookies() 
{
	return m_pCookieCollection->GetIDispatch(TRUE);
}


/********************************************************************/
/*																	*/
/* Function name : RenderCookies									*/
/* Description   : Return collected cookies as string				*/
/*																	*/
/********************************************************************/
BOOL CResponseObject::RenderCookies(CString &strCookies)
{
	return m_pCookieCollection->RenderCookies(strCookies);
}


/********************************************************************/
/*																	*/
/* Function name : GetBuffer										*/
/* Description   : Return the value of the buffer property			*/
/*																	*/
/********************************************************************/
BOOL CResponseObject::GetBuffer() 
{
	return m_bBuffer;
}


/********************************************************************/
/*																	*/
/* Function name : SetBuffer										*/
/* Description   : Set the value of the buffer property				*/
/*																	*/
/********************************************************************/
void CResponseObject::SetBuffer(BOOL bNewValue) 
{
	m_bBuffer = bNewValue;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -