Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ISAPI » General » Downloads
 
Add your own
alternative version
Go to top

Storing and retrieving binary data in ISAPI extensions

, 5 Sep 2002
An easy way to store and retrieve binary data in an ISAP dll and display them on a web page.
binarylib.zip
BinaryLib.def
BinaryLib.dsp
BinaryLib.dsw
Hello kitty what.jpg
binarylib_dll.zip
BinaryLib.dll
// BINARYLIB.CPP - Implementation file for your Internet Server
//    BinaryLib Extension

#include "stdafx.h"
#include "BinaryLib.h"

///////////////////////////////////////////////////////////////////////
// The one and only CWinApp object
// NOTE: You may remove this object if you alter your project to no
// longer use MFC in a DLL.

CWinApp theApp;

///////////////////////////////////////////////////////////////////////
// command-parsing map

BEGIN_PARSE_MAP(CBinaryLibExtension, CHttpServer)
	ON_PARSE_COMMAND(GetImage, CBinaryLibExtension, ITS_PSTR)
	ON_PARSE_COMMAND_PARAMS("Image")

	ON_PARSE_COMMAND(Default, CBinaryLibExtension, ITS_EMPTY)
	DEFAULT_PARSE_COMMAND(Default, CBinaryLibExtension)
END_PARSE_MAP(CBinaryLibExtension)


///////////////////////////////////////////////////////////////////////
// The one and only CBinaryLibExtension object

CBinaryLibExtension theExtension;


///////////////////////////////////////////////////////////////////////
// CBinaryLibExtension implementation

CBinaryLibExtension::CBinaryLibExtension()
{
}

CBinaryLibExtension::~CBinaryLibExtension()
{
}

BOOL CBinaryLibExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
	// Call default implementation for initialization
	CHttpServer::GetExtensionVersion(pVer);

	// Load description string
	TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
	ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
			IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
	_tcscpy(pVer->lpszExtensionDesc, sz);
	return TRUE;
}

BOOL CBinaryLibExtension::TerminateExtension(DWORD dwFlags)
{
	// extension is being terminated
	//TODO: Clean up any per-instance resources
	return TRUE;
}

///////////////////////////////////////////////////////////////////////
// CBinaryLibExtension command handlers

void CBinaryLibExtension::Default(CHttpServerContext* pCtxt)
{
	StartContent(pCtxt);
	WriteTitle(pCtxt);

	*pCtxt << _T("CBinaryLibExtension ISAPI by Dirk Vandenheuvel (C) 2002\r\n");

	EndContent(pCtxt);
}

// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CBinaryLibExtension, CHttpServer)
	//{{AFX_MSG_MAP(CBinaryLibExtension)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0


///////////////////////////////////////////////////////////////////////
// If your extension will not use MFC, you'll need this code to make
// sure the extension objects can find the resource handle for the
// module.  If you convert your extension to not be dependent on MFC,
// remove the comments arounn the following AfxGetResourceHandle()
// and DllMain() functions, as well as the g_hInstance global.

/*
static HINSTANCE g_hInstance;

HINSTANCE AFXISAPI AfxGetResourceHandle()
{
	return g_hInstance;
}

BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
					LPVOID lpReserved)
{
	if (ulReason == DLL_PROCESS_ATTACH)
	{
		g_hInstance = hInst;
	}

	return TRUE;
}
*/

void CBinaryLibExtension::GetImage(CHttpServerContext* pCtxt, LPCSTR sImage)
{
	int iRAWSize = 0;
	CByteArray caImage;
	CString cImage(sImage);
	cImage.Remove('\'');

	HRSRC tSrc = ::FindResource(AfxGetResourceHandle() ,cImage,"BINARY");
	if (tSrc == NULL) return;

	iRAWSize = ::SizeofResource(AfxGetResourceHandle(),tSrc);
	caImage.SetSize(iRAWSize);

	HGLOBAL hImage;
	hImage = ::LoadResource(AfxGetResourceHandle(),tSrc);
	if (hImage == NULL) return;

	BYTE* pImage = NULL;
	pImage = (BYTE*) ::LockResource(hImage);
	if (pImage == NULL) return;

	for (int iCount = 0; iCount < iRAWSize; iCount++)
		caImage.ElementAt(iCount) = pImage[iCount];

	*pCtxt << caImage;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Dirk Vandenheuvel
Architect
Belgium Belgium
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 6 Sep 2002
Article Copyright 2002 by Dirk Vandenheuvel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid