?? myisapi.cpp
字號:
// MYISAPI.CPP - Implementation file for your Internet Server
// MyISAPI Extension
#include "stdafx.h"
#include "MyISAPI.h"
//連接數據庫相關參數結構
typedef struct
{
char ip[40]; //IP地址
char username[20];//用戶名
char password[20];//密碼
char dbname[20];//數據庫名
}ConnInfo;
///////////////////////////////////////////////////////////////////////
// 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(CMyISAPIExtension, CHttpServer)
// TODO: insert your ON_PARSE_COMMAND() and
// ON_PARSE_COMMAND_PARAMS() here to hook up your commands.
// For example:
ON_PARSE_COMMAND(Getdata, CMyISAPIExtension,ITS_PSTR ITS_PSTR)
ON_PARSE_COMMAND_PARAMS("data data1")
ON_PARSE_COMMAND(Default, CMyISAPIExtension, ITS_EMPTY)
DEFAULT_PARSE_COMMAND(Default, CMyISAPIExtension)
END_PARSE_MAP(CMyISAPIExtension)
///////////////////////////////////////////////////////////////////////
// The one and only CMyISAPIExtension object
CMyISAPIExtension theExtension;
///////////////////////////////////////////////////////////////////////
// CMyISAPIExtension implementation
CMyISAPIExtension::CMyISAPIExtension()
{
}
CMyISAPIExtension::~CMyISAPIExtension()
{
}
BOOL CMyISAPIExtension::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 CMyISAPIExtension::TerminateExtension(DWORD dwFlags)
{
// extension is being terminated
//TODO: Clean up any per-instance resources
return TRUE;
}
///////////////////////////////////////////////////////////////////////
// CMyISAPIExtension command handlers
void CMyISAPIExtension::Default(CHttpServerContext* pCtxt)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("This default message was produced by the Internet");
*pCtxt << _T(" Server DLL Wizard. Edit your CMyISAPIExtension::Default()");
*pCtxt << _T(" implementation to change it.\r\n");
EndContent(pCtxt);
// printf("myisapi");
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CMyISAPIExtension, CHttpServer)
//{{AFX_MSG_MAP(CMyISAPIExtension)
//}}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 CMyISAPIExtension::Getdata(CHttpServerContext *pCtxt, char *data, char *data1 )
{
// StartContent(pCtxt);//寫HTML文件頭
// WriteTitle(pCtxt);//寫標題
//連接數據庫
// AfxOleInit();
ConnInfo myConnInfo;
_ConnectionPtr m_pConn1;
CString strConnSql01;
memset(&myConnInfo,0,sizeof(myConnInfo));
strcpy(myConnInfo.ip,"127.0.0.1"); //218.57.10.213
strcpy(myConnInfo.username,"jnhyw"); //56wto
strcpy(myConnInfo.password,"jnhyw");//cnwt5666
strcpy(myConnInfo.dbname,"jnhyw002"); //56wto
m_pConn1.CreateInstance(__uuidof(Connection));
strConnSql01.Format("PROVIDER=SQLOLEDB;DATA SOURCE=%s;UID=%s;PWD=%s;DATABASE=%s",myConnInfo.ip,myConnInfo.username,myConnInfo.password,myConnInfo.dbname);
//連接數據庫
try
{
m_pConn1->Open((_bstr_t)strConnSql01,"","",adModeUnknown);//
*pCtxt << _T("connect to db ok");
}
catch(_com_error e)
{
CString errors;
errors.Format("%s",e.ErrorMessage());
*pCtxt << errors;
}
//打開數據庫
CString sql;
_variant_t var;
_RecordsetPtr m_pRinfoset;
sql=_T("exec get_code_30_desc_search '濟寧','','青島','北京','天津','濟南','上海','棗莊','','','','','','','','','','','','','','' ");
m_pRinfoset.CreateInstance(__uuidof(Recordset));
try
{
m_pRinfoset->Open((_bstr_t)sql, // 查詢Tab_Msg表中所有字段
m_pConn1.GetInterfacePtr(), // 獲取庫接庫的IDispatch指針
adOpenKeyset, // 1
adLockReadOnly, // 1
adCmdText);
}
catch(_com_error e)
{
CString strError;
strError.Format("%s",e.ErrorMessage());
*pCtxt << strError;
}
//循環設計信息
CString BuffTemp="@@";
CString rs_ID,rs_Msg_Code,rs_Msg_Type,rs_Msg_Tel,rs_Msg_Flag,rs_Msg_Content,rs_Msg_AddTime;
while(!m_pRinfoset->adoEOF)
{
//取得信息類型
var = m_pRinfoset->GetCollect("ID");
if(var.vt != VT_NULL)
rs_ID = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_Code");
if(var.vt != VT_NULL)
rs_Msg_Code = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_Type");
if(var.vt != VT_NULL)
rs_Msg_Type = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_Tel");
if(var.vt != VT_NULL)
rs_Msg_Tel = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_Flag");
if(var.vt != VT_NULL)
rs_Msg_Flag = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_Content");
if(var.vt != VT_NULL)
rs_Msg_Content = (LPCSTR)_bstr_t(var);
var = m_pRinfoset->GetCollect("Msg_AddTime");
if(var.vt != VT_NULL)
rs_Msg_AddTime = (LPCSTR)_bstr_t(var);
BuffTemp+=rs_ID+"||"+rs_Msg_Code+"||"+rs_Msg_Type+"||"+rs_Msg_Content+"||"+rs_Msg_Tel+"||"+rs_Msg_Flag+"||"+rs_Msg_AddTime+"@@";
//指針下移
m_pRinfoset->MoveNext();
}
*pCtxt << BuffTemp;
*pCtxt << "\r\n";
*pCtxt << _T("這是你提交上來的數據:data1:");//向瀏覽器發送數據
*pCtxt <<data <<"<br>\r\n";//寫上一個換行和回車
*pCtxt << _T("data1:");
*pCtxt <<data1;
// EndContent(pCtxt);
}
void CMyISAPIExtension::WriteTitle(CHttpServerContext* pCtxt) const
{
// TODO: Add your specialized code here and/or call the base class
CHttpServer::WriteTitle(pCtxt);
}
DWORD CMyISAPIExtension::HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
{
// TODO: Add your specialized code here and/or call the base class
return CHttpServer::HttpExtensionProc(pECB);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -