📄 imgconfirmcode.cpp
字号:
// IMGCONFIRMCODE.CPP - Implementation file for your Internet Server
// ImgConfirmCode Extension
#include "stdafx.h"
#include "ImgConfirmCode.h"
#include "dibapi.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(CImgConfirmCodeExtension, CHttpServer)
// TODO: insert your ON_PARSE_COMMAND() and
// ON_PARSE_COMMAND_PARAMS() here to hook up your commands.
// For example:
ON_PARSE_COMMAND(GetImage, CImgConfirmCodeExtension, ITS_PSTR)
ON_PARSE_COMMAND_PARAMS("Image")
ON_PARSE_COMMAND(Default, CImgConfirmCodeExtension, ITS_EMPTY)
DEFAULT_PARSE_COMMAND(Default, CImgConfirmCodeExtension)
END_PARSE_MAP(CImgConfirmCodeExtension)
///////////////////////////////////////////////////////////////////////
// The one and only CImgConfirmCodeExtension object
CImgConfirmCodeExtension theExtension;
///////////////////////////////////////////////////////////////////////
// CImgConfirmCodeExtension implementation
CImgConfirmCodeExtension::CImgConfirmCodeExtension()
{
}
CImgConfirmCodeExtension::~CImgConfirmCodeExtension()
{
}
BOOL CImgConfirmCodeExtension::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 CImgConfirmCodeExtension::TerminateExtension(DWORD dwFlags)
{
// extension is being terminated
//TODO: Clean up any per-instance resources
return TRUE;
}
///////////////////////////////////////////////////////////////////////
// CImgConfirmCodeExtension command handlers
void CImgConfirmCodeExtension::Default(CHttpServerContext* pCtxt)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("图片验证码 ISAPI,VC实例编程\r\n");
EndContent(pCtxt);
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CImgConfirmCodeExtension, CHttpServer)
//{{AFX_MSG_MAP(CImgConfirmCodeExtension)
//}}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 CImgConfirmCodeExtension::GetImage(CHttpServerContext *pCtxt, LPCSTR sImage)
{
//字节数组,保存图片数据
CByteArray caImage;
//图片信息字符串,为一串数字,2位以上
CString cImage(sImage);
HDIB m_hDIB;
//根据cImage中包含的数字生成图片
//cImage中包含2位以上(包括2位)数字
int num1=atoi(cImage.Mid(0,1));
int num2=atoi(cImage.Mid(1,1));
//合并图片
::MergeDIB(num1,num2,&m_hDIB);
for(int i=2;i<cImage.GetLength();i++){
//合并图片
::MergeDIB(m_hDIB,atoi(cImage.Mid(i,1)),&m_hDIB);
}
//转换为字节数组准备输出
HDIB2ByteArray(m_hDIB,&caImage);
*pCtxt << caImage;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -