Click here to Skip to main content
15,895,142 members
Articles / Desktop Programming / MFC

Dynamically generating images in ISAPI extension using GDI+ with live demo

Rate me:
Please Sign up or sign in to vote.
3.88/5 (8 votes)
3 Oct 20022 min read 65.4K   424   26  
A class wrapper to write GDI+ images to the client browser using an ISAPI extension.
// TestISAPIMFC.cpp - Fichier d'impl�mentation pour ISAPI
//    TestISAPIMFC Extension

#include "stdafx.h"
#include "TestISAPIMFC.h"
#include "GDIpISAPI.h"
#include "GDIpExample.h"

// Seul et unique objet CWinApp
// REMARQUE�: Vous pouvez supprimer cet objet si vous modifiez votre projet afin de ne plus
// utiliser MFC dans une DLL.

CWinApp theApp;


// table d'analyse des commandes

BEGIN_PARSE_MAP(CTestISAPIMFCExtension, CHttpServer)
	// TODO�: ins�rez ici ON_PARSE_COMMAND() et 
	// ON_PARSE_COMMAND_PARAMS() pour traiter vos commandes.
	// Par exemple�:

	ON_PARSE_COMMAND(Default, CTestISAPIMFCExtension, ITS_EMPTY)
	DEFAULT_PARSE_COMMAND(Default, CTestISAPIMFCExtension)
	ON_PARSE_COMMAND(Render,  CTestISAPIMFCExtension, ITS_PSTR ITS_I2 ITS_I2)
	ON_PARSE_COMMAND_PARAMS("type=png width=320 height=200")

END_PARSE_MAP(CTestISAPIMFCExtension)



// Seul et unique objet CTestISAPIMFCExtension

CTestISAPIMFCExtension theExtension;



// Impl�mentation CTestISAPIMFCExtension
CTestISAPIMFCExtension::CTestISAPIMFCExtension()
{
}

CTestISAPIMFCExtension::~CTestISAPIMFCExtension()
{
}

BOOL CTestISAPIMFCExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
	// Appelez l'impl�mentation par d�faut pour l'initialisation
	CHttpServer::GetExtensionVersion(pVer);

	// Initialize GDI+
	m_GDIpInitializer.Initialize();

	// Chargez la cha�ne de description
	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 CTestISAPIMFCExtension::TerminateExtension(DWORD dwFlags)
{
	// l'extension est arr�t�e
	//TODO�: nettoyez les ressources par instance
	m_GDIpInitializer.Deinitialize();

	return TRUE;
}


// Gestionnaire de commandes CTestISAPIMFCExtension

void CTestISAPIMFCExtension::Default(CHttpServerContext* pCtxt)
{
	CGdipExample* pExample = new CGdipExample(this, pCtxt, "png", 480,300);
	pExample->Render();
	delete pExample;
}

void CTestISAPIMFCExtension::Render(CHttpServerContext* pCtxt, LPTSTR pszType, int iWidth, int iHeight)
{
	CGdipExample* pExample = new CGdipExample(this, pCtxt, pszType, iWidth,iHeight);
	pExample->Render();
	delete pExample;
}

// Si votre extension ne doit pas utiliser MFC, vous aurez besoin de ce code pour vous assurer
// que les objets d'extension peuvent trouver le handle de ressource pour le
// module. Si vous convertissez votre extension afin qu'elle ne soit pas d�pendante de MFC,
// supprimez les commentaires autour des fonctions AfxGetResourceHandle()
// et DllMain() suivantes, ainsi que 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;
}

****/

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


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions