|
各位达人:
小弟最近要做通话记录扩展,需要读取EDB数据库(pim.vol中的clog.db),经过一番探索终于有了些进展,但是现在却卡在数据库信息获取/SEEK/READ/以及打开时排序上,上面几个操作都不成功,请高人帮忙看看问题在哪里。
代码和说明如下
C/C++ code
// 初始化:
void CedbDlg::init(HWND hwnd)
{
HRESULT hr = S_OK;
CREATE_INVALIDGUID(&m_ceguid);//m_ceguid是成员变量
BOOL b = CeMountDBVolEx(&m_ceguid, _T("\\pim.vol"), 0, OPEN_EXISTING);
m_ceoid = 0;
m_session = CeCreateSession(&m_ceguid);
CENOTIFYREQUEST *pReq = (CENOTIFYREQUEST *)LocalAlloc(LPTR, sizeof(CENOTIFYREQUEST));
pReq->dwSize = sizeof(CENOTIFYREQUEST);
pReq->hwnd = hwnd;
pReq->hHeap = NULL;
pReq->dwFlags = CEDB_EXNOTIFICATION;
// 问题1:这里本来打算打开时排序,但是发现一旦传入这个参数就会打开失败,
//GetLastError()报ERROR_INVALID_PARAMETER,
//所以在下面的函数中我把这个参数换成了NULL,打开成功
//为啥不能指定排序呢?
SORTORDERSPECEX *pSort = (SORTORDERSPECEX *)LocalAlloc(LPTR, sizeof(SORTORDERSPECEX));
pSort->wVersion = SORTORDERSPECEX_VERSION;
pSort->wNumProps = 0;
pSort->wKeyFlags = 0;
pSort->wReserved = 0;
pSort->rgPropID[0] = PRPID_NUMBER;
pSort->rgPropID[1] = PRPID_START_TIME;
pSort->rgdwFlags[0] = CEDB_SORT_CASEINSENSITIVE;
pSort->rgdwFlags[1] = CEDB_SORT_DESCENDING;
m_hdb = ::CeOpenDatabaseInSession(m_session,&m_ceguid,
&m_ceoid, _T("clog.db"), /*pSort*/NULL, 0, pReq);
ASSERT(m_hdb != HANDLE_INVALID_VALUE);
refresh();
if(pSort) LocalFree(pSort);
if(pReq) LocalFree(pReq);
DWORD err = GetLastError();
}
// 读取函数:
void CedbDlg::refresh()
{
CEOIDINFOEX* poidInfo = (CEOIDINFOEX*) LocalAlloc(LPTR, sizeof(CEOIDINFOEX));
// 按照MSDN上的介绍,这里一定要填1,但是下面的CeOidGetInfoEx2会失败,
//返回ERROR_INVALID_PARAMETER,我也试过CeOidGetInfoEx,一样的结果
poidInfo->wVersion = 1;
if(!CeOidGetInfoEx2(&m_ceguid,m_ceoid,poidInfo))
{
TRACE(L"CeOidGetInfoEx Fail err 0x%x\n", GetLastError());
return;
}
DWORD dwIndex = 0;
CEOID CEoid =0;
int unitIndex = 0;
int iCount = poidInfo->infDatabase.dwNumRecords;
LocalFree(poidInfo);
if(iCount > 0)
{
PBYTE pBuff;
WORD wProps;
DWORD dwRecSize;
PCEPROPVAL pRecord;
for(int i = 0; i < iCount; ++ i)
{
DWORD err;
////////////////////////移动记录指针,失败
CEoid = CeSeekDatabaseEx(m_hdb,CEDB_SEEK_BEGINNING,i,0, &dwIndex);
err = GetLastError();
//ASSERT(CEoid !=0);
pBuff = 0;
////////////////////////读取所有字段值,失败
CEoid = CeReadRecordProps(m_hdb,CEDB_ALLOWREALLOC,&wProps,NULL,&(LPBYTE)pBuff,&dwRecSize);
err = GetLastError();
//ASSERT(CEoid !=0);
pRecord = (PCEPROPVAL)pBuff;
bool bf = true;
LocalFree(pBuff);
}
}
} |
|