CEDB 读取cemail.vol实例
众所周知cemail是与短信有关的数据库。由于cemail属于CEDB(pim属于EDB),如果采用EDB的API去访问cemail经常会产生以下两种错误:
1. 另一个程序正在使用此文件,进程无法访问。.
2. 参数死活无效。
以下程序简单的阐述了访问cemail的步骤,不完善的地方请补充:
#define EDB
#include "stdafx.h"
#include <windows.h>
#include <windbase.h>
#include <commctrl.h>
BOOL Test_EDB06( TCHAR *pwszVolName, TCHAR *pwszDBName )
{
CEGUID ceguidCemail;
CEOID ceoidFind;
CEOID coidRecord;
CEOID oidDB;
BOOL bResult;
DWORD dwError;
bResult = FALSE;
coidRecord = 0;
ceoidFind = 0;
oidDB = 0;
dwError = 0;
// Fill in the DBInfo structure
CREATE_SYSTEMGUID( &ceguidCemail );
if(!CeMountDBVol( &ceguidCemail, pwszVolName , OPEN_EXISTING))
{
bResult = FALSE;
return FALSE;
}
HANDLE hSession = CeOpenDatabaseEx2(&ceguidCemail, &oidDB, pwszDBName, 0, CEDB_AUTOINCREMENT, NULL );
if ( hSession == INVALID_HANDLE_VALUE )
{
dwError = GetLastError();
return FALSE;
}
ceoidFind = CeSeekDatabaseEx(hSession, CEDB_SEEK_BEGINNING, 0, 0, NULL);
if (!ceoidFind )
{
dwError = GetLastError();
return FALSE;
}
WORD wNumProps = 0;
CEPROPVAL *pRecord = NULL;
DWORD dwBufSize = 0;
while (coidRecord = CeReadRecordPropsEx(hSession, CEDB_ALLOWREALLOC, &wNumProps, NULL, (LPBYTE *)&pRecord, &dwBufSize, NULL))
{
for (int i = 0; i < wNumProps; i++)
{
// you can do something
}
}
CeUnmountDBVol(&ceguidCemail);
return bResult;
}
int _tmain(int argc, _TCHAR* argv[])
{
Test_EDB06( L"cemail.vol", _T("fldr31000024") );
return 0;
}
地址:http://www.devdiv.net/bbs/archiver/tid-8579.html