Currently viewing: GipsySoft » Front Page» Articles


Simple class that will allow easy parsing of the QUERY_STRING environment variable or a passed string. It will also decode the parameters on the way through

NOT tested in UNICODE.

To make use of the class you will need to derive from it and provide a version of OnParameter(...)

void OnParameter( LPCTSTR pcszParam, UINT uParamLength, LPCTSTR pcszValue, UINT uValueLength ) = 0


class CMyParameters: public CHTTPParametersABC
//	Derive from the base class
		: m_bPassword( false )

	void OnParameter( LPCTSTR pcszParam
		, UINT uParamLength, LPCTSTR pcszValue, UINT uValueLength )
		if( *pcszParam == 'p' )
			m_bPassword = true;

	bool m_bPassword;

void test()
	CMyParameters param;
	if( param.m_bPassword )
		//	Do something useful

Because the parameters are decoded before OnParameter is called you can make use of them straight away. Also, no extra allocations are made for each parameter and no unnecessary copying is needed.


Click to view the source code