代码很简单就是操作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
OID: 1077960704
Version: 2
2 RECS,
Type: 25
Size: 0
Flags: 0x17
5 sort orders:
==========
Sort 0 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x1200
PID[0]=0x10000066
(Pr=0x1000,Ty=102)
PFL[0]=0x0
==========
Sort 1 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x10420040
(Pr=0x1042,Ty=64)
PFL[0]=0x0
==========
Sort 2 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x22000b
(Pr=0x22,Ty=11)
PFL[0]=0x0
==========
Sort 3 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x10400013
(Pr=0x1040,Ty=19)
PFL[0]=0x0
==========
Sort 4 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x1b0013
(Pr=0x1b,Ty=19)
PFL[0]=0x0
==========
-------------------
[1] CategoryAssocDB
OID: 1078239245
Version: 2
0 RECS,
Type: 83
Size: 0
Flags: 0x17
2 sort orders:
==========
Sort 0 has 2 props:
[wVersion ]= 2
[wKeyFlags]=0x200
PID[0]=0x10013
(Pr=0x1,Ty=19)
PFL[0]=0x0
PID[1]=0x20003
(Pr=0x2,Ty=3)
PFL[1]=0x0
==========
Sort 1 has 2 props:
[wVersion ]= 2
[wKeyFlags]=0x200
PID[0]=0x20003
(Pr=0x2,Ty=3)
PFL[0]=0x0
PID[1]=0x10013
(Pr=0x1,Ty=19)
Version: 2
2 RECS,
Type: 25
Size: 0
Flags: 0x17
5 sort orders:
==========
Sort 0 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x1200
PID[0]=0x10000066
(Pr=0x1000,Ty=102)
PFL[0]=0x0
==========
Sort 1 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x10420040
(Pr=0x1042,Ty=64)
PFL[0]=0x0
==========
Sort 2 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x22000b
(Pr=0x22,Ty=11)
PFL[0]=0x0
==========
Sort 3 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x10400013
(Pr=0x1040,Ty=19)
PFL[0]=0x0
==========
Sort 4 has 1 props:
[wVersion ]= 2
[wKeyFlags]=0x0
PID[0]=0x1b0013
(Pr=0x1b,Ty=19)
PFL[0]=0x0
==========
-------------------
[1] CategoryAssocDB
OID: 1078239245
Version: 2
0 RECS,
Type: 83
Size: 0
Flags: 0x17
2 sort orders:
==========
Sort 0 has 2 props:
[wVersion ]= 2
[wKeyFlags]=0x200
PID[0]=0x10013
(Pr=0x1,Ty=19)
PFL[0]=0x0
PID[1]=0x20003
(Pr=0x2,Ty=3)
PFL[1]=0x0
==========
Sort 1 has 2 props:
[wVersion ]= 2
[wKeyFlags]=0x200
PID[0]=0x20003
(Pr=0x2,Ty=3)
PFL[0]=0x0
PID[1]=0x10013
(Pr=0x1,Ty=19)