代码很简单就是操作EDB数据库,先按开始时间降序排序,然后删除第一条匹配的记录。
1 bool DeleteLastCallLogByNumber(LPCTSTR lpszNumber)
2 {
3 typedef enum
4 {
5 CT_Reserved=0,
6 CT_Outgoing=1,
7 CT_Connected=2,
8 CT_Ended=4,
9 CT_Voice_Data=8,
10 CT_Roam=16
11 }CallType;
12
13 DebugMsg(_T("DeleteLastCallLogByNumber Enter"));
14 bool bRetn=false;
15 CEGUID ceguid;
16 if(CeMountDBVolEx(&ceguid, _T("\\pim.vol"), NULL , OPEN_EXISTING))
17 {
18 DebugMsg(_T("DeleteLastCallLogByNumber!CeMountDBVolEx Pass"));
19 CEOID ceoid=0;
20 SORTORDERSPECEX pSort={CEOIDINFOEX_VERSION,1,0};
21 pSort.rgPropID[0]=0x20040; //按StartTime排序
22 pSort.rgdwFlags[0]=CEDB_SORT_DESCENDING;
23 HANDLE hndDb = CeOpenDatabaseInSession(NULL,&ceguid,&ceoid,_T("clog.db"),&pSort,CEDB_AUTOINCREMENT,NULL);
24 if(hndDb != INVALID_HANDLE_VALUE)
25 {
26 DebugMsg(_T("DeleteLastCallLogByNumber!CeOpenDatabaseInSession Pass"));
27 if(0!=CeSeekDatabase(hndDb,CEDB_SEEK_BEGINNING,0,NULL))
28 {
29 DebugMsg(_T("DeleteLastCallLogByNumber!CeSeekDatabase Pass"));
30 CEOID ceOid;
31 WORD propID=0;
32 PCEPROPVAL lpBuffer=NULL;
33 DWORD lpcbBuffer;
34 PCEPROPVAL propVal;
35 while(0!=(ceOid=CeReadRecordProps(hndDb,CEDB_ALLOWREALLOC,&propID,NULL,(LPBYTE*)&lpBuffer,&lpcbBuffer)))
36 {
37 int CallType;
38 LPWSTR Number;
39 for(int i=0;i<propID;++i)
40 {
41 propVal=lpBuffer+i;
42 switch(HIWORD(propVal->propid))
43 {
44 case 6:
45 Number = propVal->val.lpwstr;
46 break;
47 case 4:
48 CallType = propVal->val.lVal;
49 break;
50 }
51 }
52
53 if((CallType&CT_Outgoing) && _tcscmp(Number,lpszNumber)==0)
54 {
55 if(CeDeleteRecord(hndDb,ceOid))
56 {
57 DebugMsg(_T("DeleteLastCallLogByNumber!CeDeleteRecord Pass"));
58 bRetn=true;
59 }
60 else
61 {
62 DebugMsg(_T("DeleteLastCallLogByNumber!CeDeleteRecord Fail"));
63 }
64 break;
65 }
66 }
67 if(lpBuffer)LocalFree((LPBYTE)lpBuffer);
68 }
69 CloseHandle(hndDb);
70 }
71 CeFlushDBVol(&ceguid);
72 CeUnmountDBVol(&ceguid);
73 }
74
75 return bRetn;
76 }
2 {
3 typedef enum
4 {
5 CT_Reserved=0,
6 CT_Outgoing=1,
7 CT_Connected=2,
8 CT_Ended=4,
9 CT_Voice_Data=8,
10 CT_Roam=16
11 }CallType;
12
13 DebugMsg(_T("DeleteLastCallLogByNumber Enter"));
14 bool bRetn=false;
15 CEGUID ceguid;
16 if(CeMountDBVolEx(&ceguid, _T("\\pim.vol"), NULL , OPEN_EXISTING))
17 {
18 DebugMsg(_T("DeleteLastCallLogByNumber!CeMountDBVolEx Pass"));
19 CEOID ceoid=0;
20 SORTORDERSPECEX pSort={CEOIDINFOEX_VERSION,1,0};
21 pSort.rgPropID[0]=0x20040; //按StartTime排序
22 pSort.rgdwFlags[0]=CEDB_SORT_DESCENDING;
23 HANDLE hndDb = CeOpenDatabaseInSession(NULL,&ceguid,&ceoid,_T("clog.db"),&pSort,CEDB_AUTOINCREMENT,NULL);
24 if(hndDb != INVALID_HANDLE_VALUE)
25 {
26 DebugMsg(_T("DeleteLastCallLogByNumber!CeOpenDatabaseInSession Pass"));
27 if(0!=CeSeekDatabase(hndDb,CEDB_SEEK_BEGINNING,0,NULL))
28 {
29 DebugMsg(_T("DeleteLastCallLogByNumber!CeSeekDatabase Pass"));
30 CEOID ceOid;
31 WORD propID=0;
32 PCEPROPVAL lpBuffer=NULL;
33 DWORD lpcbBuffer;
34 PCEPROPVAL propVal;
35 while(0!=(ceOid=CeReadRecordProps(hndDb,CEDB_ALLOWREALLOC,&propID,NULL,(LPBYTE*)&lpBuffer,&lpcbBuffer)))
36 {
37 int CallType;
38 LPWSTR Number;
39 for(int i=0;i<propID;++i)
40 {
41 propVal=lpBuffer+i;
42 switch(HIWORD(propVal->propid))
43 {
44 case 6:
45 Number = propVal->val.lpwstr;
46 break;
47 case 4:
48 CallType = propVal->val.lVal;
49 break;
50 }
51 }
52
53 if((CallType&CT_Outgoing) && _tcscmp(Number,lpszNumber)==0)
54 {
55 if(CeDeleteRecord(hndDb,ceOid))
56 {
57 DebugMsg(_T("DeleteLastCallLogByNumber!CeDeleteRecord Pass"));
58 bRetn=true;
59 }
60 else
61 {
62 DebugMsg(_T("DeleteLastCallLogByNumber!CeDeleteRecord Fail"));
63 }
64 break;
65 }
66 }
67 if(lpBuffer)LocalFree((LPBYTE)lpBuffer);
68 }
69 CloseHandle(hndDb);
70 }
71 CeFlushDBVol(&ceguid);
72 CeUnmountDBVol(&ceguid);
73 }
74
75 return bRetn;
76 }
另附转载的一篇pim.vol数据库内部信息的文章
以下是本人从pim.vol中读取的数据库信息,由此可以对数据库有更深入的了解。
********************
12 databases found!
PIM.VOL GUID: 3306647807
********************
[0] Appointments Database
-------------------
[1] CategoryAssocDB