資源簡介
亦思驗證碼C++調用封裝庫,支持網絡圖片,本地圖片,內存圖片的識別。在官方的dll實例中只有VB、delp、易語言的例子,沒有VC的,今天剛好用到,簡單封裝了下,分享下,討論下:QQ:103.626,571
//////////////////調用示例//////////////////////
int item = 3;
cVcode::init("all.fc", "123456");
//網絡地址驗證碼
CString code = cVcode::getNetCode("http://www.xxx.net/UsreAdmin/HouseMgr/validatecode.asp", item);
wcout<<code.GetString()<<endl;
//本地驗證碼
CString code2 = cVcode::getLocalCode("c:/yfwcode.bmp", item);
wcout<<code2.GetString()<<endl;
//內存中的驗證碼
HttpLib lib;
CMemFile file;
lib.getFile("http://www.xxx.net/UsreAdmin/HouseMgr/validatecode.asp", &file);
CString code3 = cVcode::getMemCode(file, item);
wcout<<code3.GetString()<<endl;

代碼片段和文件信息
#include?“StdAfx.h“
#include?“cVcode.h“
using?namespace?std;
void?cVcode::exit()
{
isInit?=?FALSE;
FreeLibrary(hdll);
}
BOOL?cVcode::init(?char?*?libPath?char?*?pwd?)
{
try{
hdll?=?LoadLibrary(L“ycode.dll“);
loadcode?=?(lpLoadCode)GetProcAddress(hdll?“loadcode“);
recognition?=?(lpRecognition)GetProcAddress(hdll?“Recognitiond“);
//加載驗證碼庫
loadcode(00libPathpwd);
isInit?=?TRUE;
return?TRUE;
}catch(exception?&e){
cout<<“Exception:“< return?FALSE;
}
}
CString?cVcode::getNetCode(?CString?&picUrl?int?&itemId?)
{
if?(!isInit)?return?““;
USES_CONVERSION;
char?*?_picUrl?=?T2A(picUrl);
try{
char?*?code?=?recognition(itemId?0?0?_picUrl?““);
CString?rst;
rst.Format(L“%s“?A2T(code));
return?rst;
}catch(exception?&e){
cout<<“Exception:“< return?““;
}
}
CString?cVcode::getLocalCode(?CString?&picPath?int?&itemId?)
{
if?(!isInit)?return?““;
USES_CONVERSION;
char?*?_picPath?=?T2A(picPath);
try{
char?*?code?=?recognition(itemId?0?0?““?_picPath);
CString?rst;
rst.Format(L“%s“?A2T(code));
return?rst;
}catch(exception?&e){
cout<<“Exception:“< return?““;
}
}
CString?cVcode::getMemCode(?CMemFile?&file?int?&itemId?)
{
if?(!isInit)?return?““;
USES_CONVERSION;
try{
int?dataLen?=?file.GetLength();
byte?*?dataByte?=?new?byte[dataLen];
file.SeekToBegin();
file.Read(dataByte?dataLen);
char?*?code?=?recognition(itemId?(long)dataByte?dataLen?““?““);
delete?[]?dataByte;
CString?rst;
rst.Format(L“%s“?A2T(code));
return?rst;
}catch(exception?&e){
cout<<“Exception:“< return?““;
}
}
lpRecognition?cVcode::recognition?=?NULL;
lpLoadCode?cVcode::loadcode?=?NULL;
HINSTANCE?cVcode::hdll?=?NULL;
BOOL?cVcode::isInit?=?FALSE;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1373??2011-01-21?18:50??cVcode.h
?????文件???????1893??2011-01-21?18:39??cVcode.cpp
?????文件????????595??2011-01-21?18:58??使用例子.txt
-----------?---------??----------?-----??----
?????????????????3861????????????????????3
評論
共有 條評論