⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kvlist.cpp

📁 使用CT-C开发的一个CTI软电话系统,ActiveX形式的,仅供参考
💻 CPP
字号:
// KVList.cpp : Implementation of CKVList
#include "stdafx.h"
#include "ctcv4.h"
#include "KVPair.h"
#include "KVList.h"

DECLARE_CASTER(CKVList, IKVList)
DECLARE_CREATOR(CKVList, IKVList)
DECLARE_CREATOR(CKVPair, IKVPair)

LPKVLIST CreateKVList(TKVList *pKVList)
{
	if(!pKVList) return(NULL);
	CKVList *pList = NULL;
	IKVList *iList = NULL;
	TKVList *pl = TKVListDup(pKVList);
	if(pl) {
		if(SUCCEEDED(CreateClass(&pList, &iList))) {
			TKVListFree(pList->m_pKVList);
			pList->m_pKVList = pl;
		} else
			TKVListFree(pl);
	}
	return(iList);
}

/////////////////////////////////////////////////////////////////////////////
// CKVList

STDMETHODIMP_(LPKVLIST) CKVList::Dup()
{
	// TODO: Add your implementation code here
	return(CreateKVList(m_pKVList));
}

STDMETHODIMP_(KVRESULTS) CKVList::AddString(BSTR key, BSTR value)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key && value) {
		char keybuf[256], valuebuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		WideCharToMultiByte(CP_ACP, 0, value, -1, valuebuf, 256, NULL, NULL);
		res = (KVRESULTS)TKVListAddString(m_pKVList, keybuf, valuebuf);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::AddInt(BSTR key, int value)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		res = (KVRESULTS)TKVListAddInt(m_pKVList, keybuf, value);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::AddList(BSTR key, LPKVLIST value)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	CKVList *pList = I2C(value);
	if(key && pList) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		res = (KVRESULTS)TKVListAddList(m_pKVList, keybuf, pList->m_pKVList);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::AddBinary(BSTR key, int length, byte *value)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key && length && value) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		res = (KVRESULTS)TKVListAddBinary(m_pKVList, keybuf, value, length);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::DeletePair(BSTR key)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		res = (KVRESULTS)TKVListDeletePair(m_pKVList, keybuf);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::DeleteAll()
{
	// TODO: Add your implementation code here
	return((KVRESULTS)TKVListDeleteAll(m_pKVList));
}

STDMETHODIMP_(KVRESULTS) CKVList::InitScanLoop()
{
	// TODO: Add your implementation code here
	return((KVRESULTS)TKVListInitScanLoop(m_pKVList));
}

STDMETHODIMP_(LPKVPAIR) CKVList::NextPair()
{
	// TODO: Add your implementation code here
	CKVPair *pPair = NULL;
	IKVPair *iPair = NULL;
	TKVPair *p = TKVListNextPair(m_pKVList);
	if(p && SUCCEEDED(CreateClass(&pPair, &iPair))) {
		if(!pPair->Initialize(p)) {
			iPair->Release();
			iPair = NULL;
		}
	}
	return(iPair);
}

STDMETHODIMP_(KVRESULTS) CKVList::GetStringValue(BSTR key, BSTR *pVal)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		*pVal = C2B(TKVListGetStringValue(m_pKVList, keybuf, (TKVResult *)&res));
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::GetIntValue(BSTR key, int *pVal)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		*pVal = TKVListGetIntValue(m_pKVList, keybuf, (TKVResult *)&res);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::GetListValue(BSTR key, LPKVLIST *pVal)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		*pVal = CreateKVList(TKVListGetListValue(m_pKVList, keybuf, (TKVResult *)&res));
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::GetBinaryValue(BSTR key, byte **pVal)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		*pVal = TKVListGetBinaryValue(m_pKVList, keybuf, (TKVResult *)&res);
	}
	return(res);
}

STDMETHODIMP_(KVRESULTS) CKVList::GetPair(BSTR key, LPKVPAIR *pVal)
{
	// TODO: Add your implementation code here
	KVRESULTS res = KVR_Error;
	if(key) {
		char keybuf[256];
		WideCharToMultiByte(CP_ACP, 0, key, -1, keybuf, 256, NULL, NULL);
		CKVPair *pPair = NULL;
		IKVPair *iPair = NULL;
		TKVPair *p = TKVListGetPair(m_pKVList, keybuf, (TKVResult *)&res);
		if(p && SUCCEEDED(CreateClass(&pPair, &iPair))) {
			if(!pPair->Initialize(p)) {
				iPair->Release();
				iPair = NULL;
			}
		}
		*pVal = iPair;
	}
	return(res);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -