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

📄 requestobject.cpp

📁 ASP切分器
💻 CPP
字号:
/********************************************************************/
/*																	*/
/*  RequestObject.cpp												*/
/*																	*/
/*  Implementation of the CRequestObject class.						*/
/*																	*/
/*  Programmed by Pablo van der Meer								*/
/*	http://www.pablovandermeer.nl									*/
/*																	*/
/*  Last updated: 22 february 2003									*/
/*																	*/
/********************************************************************/

#include "stdafx.h"
#include "RequestObject.h"

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


IMPLEMENT_DYNCREATE(CRequestObject, CCmdTarget)


/********************************************************************/
/*																	*/
/* Function name : CRequestObject::CRequestObject					*/
/* Description   : Constructor										*/
/*																	*/
/********************************************************************/
CRequestObject::CRequestObject()
{
	EnableAutomation();

	try 
	{
		// create instance of "Scripting.Dictionary" using smart pointer for QueryString collection
		HRESULT hResult = m_pQueryStringCollection.CreateInstance(L"Scripting.Dictionary");
		if (SUCCEEDED(hResult))
		{
			TRACE0("QueryString collection succesfully loaded!\n");
			AddQueryStringKey("Name", "Pablo");
			AddQueryStringKey("Country", "Holland");
		}
		// create instance of "Scripting.Dictionary" using smart pointer for Form collection
		hResult = m_pFormCollection.CreateInstance(L"Scripting.Dictionary");
		if (SUCCEEDED(hResult))
		{
			TRACE0("Form collection succesfully loaded!\n");
		}
		// create instance of "Scripting.Dictionary" using smart pointer for ServerVariables collection
		hResult = m_pServerVariablesCollection.CreateInstance(L"Scripting.Dictionary");
		if (SUCCEEDED(hResult))
		{
			TRACE0("ServerVariables collection succesfully loaded!\n");
			InitializeServerVariables();
		}
		// create instance of "Scripting.Dictionary" using smart pointer for Cookies collection
		hResult = m_pCookiesCollection.CreateInstance(L"Scripting.Dictionary");
		if (SUCCEEDED(hResult))
		{
			TRACE0("Cookies collection succesfully loaded!\n");
			AddCookiesKey("myCookie", "Pablo");
		}
	}
	// Catch all MFC exceptions, including COleExceptions.
	// OS exceptions will not be caught.
	catch (CException *e) 
	{
		CString strError;

		strError.Format("%s(%d): OLE Exception caught: SCODE = %x", 
			__FILE__, __LINE__, COleException::Process(e));

		TRACE1("%s\n", strError);

		char szError[128];

		e->GetErrorMessage(szError, sizeof(szError));
		
		TRACE1("%s\n", szError);

		e->Delete();
	}
	catch (_com_error e)
	{
	}
}


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


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


BEGIN_DISPATCH_MAP(CRequestObject, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CRequestObject)
	DISP_FUNCTION(CRequestObject, "QueryString", QueryString, VT_DISPATCH, VTS_NONE)
	DISP_FUNCTION(CRequestObject, "Form", Form, VT_DISPATCH, VTS_NONE)
	DISP_FUNCTION(CRequestObject, "ServerVariables", ServerVariables, VT_DISPATCH, VTS_NONE)
	DISP_FUNCTION(CRequestObject, "Cookies", Cookies, VT_DISPATCH, VTS_NONE)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

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

// {8391C3A1-145D-424B-891E-51A5836FA1B4}
static const IID IID_IRequestObject =
{ 0x8391c3a1, 0x145d, 0x424b, { 0x89, 0x1e, 0x51, 0xa5, 0x83, 0x6f, 0xa1, 0xb4 } };

BEGIN_INTERFACE_MAP(CRequestObject, CCmdTarget)
	INTERFACE_PART(CRequestObject, IID_IRequestObject, Dispatch)
END_INTERFACE_MAP()


/********************************************************************/
/*																	*/
/* Function name : QueryString										*/
/* Description   : Return QueryStringCollection IDispatch pointer 	*/
/*																	*/
/********************************************************************/
LPDISPATCH CRequestObject::QueryString() 
{
	m_pQueryStringCollection->AddRef();
	return m_pQueryStringCollection;
}


/********************************************************************/
/*																	*/
/* Function name : Form												*/
/* Description   : Return Form IDispatch pointer 					*/
/*																	*/
/********************************************************************/
LPDISPATCH CRequestObject::Form() 
{
	m_pFormCollection->AddRef();
	return m_pFormCollection;
}


/********************************************************************/
/*																	*/
/* Function name : ServerVariables									*/
/* Description   : Return ServerVariables IDispatch pointer 		*/
/*																	*/
/********************************************************************/
LPDISPATCH CRequestObject::ServerVariables() 
{
	m_pServerVariablesCollection->AddRef();
	return m_pServerVariablesCollection;
}


/********************************************************************/
/*																	*/
/* Function name : Cookies											*/
/* Description   : Return Cookies IDispatch pointer 				*/
/*																	*/
/********************************************************************/
LPDISPATCH CRequestObject::Cookies() 
{
	m_pCookiesCollection->AddRef();
	return m_pCookiesCollection;
}


/********************************************************************/
/*																	*/
/* Function name : AddQueryStringKey								*/
/* Description   : Add an entry to the QueryString collection.		*/
/*																	*/
/********************************************************************/
void CRequestObject::AddQueryStringKey(LPCTSTR lpszKey, LPCTSTR lpszValue)
{
	COleVariant varKey(lpszKey);
	COleVariant varValue(lpszValue);

	HRESULT hResult = m_pQueryStringCollection->Add(varKey, varValue);
	if (SUCCEEDED(hResult))
	{
		TRACE0("Key succesfully added to QueryString collection\n");
	}
}


/********************************************************************/
/*																	*/
/* Function name : AddFormKey										*/
/* Description   : Add an entry to the Form collection.				*/
/*																	*/
/********************************************************************/
void CRequestObject::AddFormKey(LPCTSTR lpszKey, LPCTSTR lpszValue)
{
	COleVariant varKey(lpszKey);
	COleVariant varValue(lpszValue);

	HRESULT hResult = m_pFormCollection->Add(varKey, varValue);
	if (SUCCEEDED(hResult))
	{
		TRACE0("Key succesfully added to Form collection\n");
	}
}


/********************************************************************/
/*																	*/
/* Function name : AddServerVariablesKey							*/
/* Description   : Add an entry to the ServerVariables collection.	*/
/*																	*/
/********************************************************************/
void CRequestObject::AddServerVariablesKey(LPCTSTR lpszKey, LPCTSTR lpszValue)
{
	COleVariant varKey(lpszKey);
	COleVariant varValue(lpszValue);

	HRESULT hResult = m_pServerVariablesCollection->Add(varKey, varValue);
	if (SUCCEEDED(hResult))
	{
		TRACE0("Key succesfully added to ServerVariables collection\n");
	}
}


/********************************************************************/
/*																	*/
/* Function name : AddCookiesKey									*/
/* Description   : Add an entry to the Cookies collection.			*/
/*																	*/
/********************************************************************/
void CRequestObject::AddCookiesKey(LPCTSTR lpszKey, LPCTSTR lpszValue)
{
	COleVariant varKey(lpszKey);
	COleVariant varValue(lpszValue);

	HRESULT hResult = m_pCookiesCollection->Add(varKey, varValue);
	if (SUCCEEDED(hResult))
	{
		TRACE0("Key succesfully added to Cookies collection\n");
	}
}


/********************************************************************/
/*																	*/
/* Function name : InitializeServerVariables						*/
/* Description   : Populate the ServerVariables collection.			*/
/*																	*/
/********************************************************************/
void CRequestObject::InitializeServerVariables()
{
	// TODO: fill with 'real' values ...

    AddServerVariablesKey("HTTP_USER_AGENT", "Pablo's Internet Browser");
    AddServerVariablesKey("PATH_TRANSLATED", "filename.txt");
    
    char szBuff[MAX_COMPUTERNAME_LENGTH + 1];
	DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;

    GetUserName(szBuff, &dwSize);
    AddServerVariablesKey("LOGON_USER", szBuff);
    
	// failes on Windows 2000/XP !
    GetComputerName(szBuff, &dwSize);
	AddServerVariablesKey("SERVER_NAME", szBuff);

	AddServerVariablesKey("SERVER_SOFTWARE", "Pablo Software Solutions ASP demo/1.0");
	AddServerVariablesKey("SERVER_PROTOCOL", "HTTP/1.0");

	AddServerVariablesKey("LOCAL_ADDR", "127.0.0.1");
	AddServerVariablesKey("REMOTE_ADDR", "127.0.0.1");
	AddServerVariablesKey("REMOTE_HOST", "127.0.0.1");
}

⌨️ 快捷键说明

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