实现WM下删除最后一条匹配的通话记录

代码很简单就是操作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 }

另附转载的一篇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)
      PFL[1]=0x0
    ==========
-------------------
[2] CategoryMainDB
    OID: 1078239238
    Version: 2
    4 RECS,
    Type: 82
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x2001f
       (Pr=0x2,Ty=31)
      PFL[0]=0x2
    ==========
    Sort 1 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x1200
      PID[0]=0x10066
       (Pr=0x1,Ty=102)
      PFL[0]=0x0
    ==========
-------------------
[3] clog.db
    OID: 1078153228
    Version: 2
    259 RECS,
    Type: 0
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x20040
       (Pr=0x2,Ty=64)
      PFL[0]=0x1
    ==========
    Sort 1 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x1200
      PID[0]=0x10000066
       (Pr=0x1000,Ty=102)
      PFL[0]=0x0
    ==========
-------------------
[4] Contacts Database
    OID: 1078034448
    Version: 2
    62 RECS,
    Type: 24
    Size: 0
    Flags: 0x17
    14 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x1200
      PID[0]=0x10000066
       (Pr=0x1000,Ty=102)
      PFL[0]=0x0
    ==========
    Sort 1 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[0]=0x2
      PID[1]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[1]=0x4
    ==========
    Sort 2 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[0]=0x4
      PID[1]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[1]=0x2
    ==========
    Sort 3 has 4 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x8a001f
       (Pr=0x8a,Ty=31)
      PFL[0]=0x2
      PID[1]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[1]=0x2
      PID[2]=0x8b001f
       (Pr=0x8b,Ty=31)
      PFL[2]=0x2
      PID[3]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[3]=0x4
    ==========
    Sort 4 has 4 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[0]=0x4
      PID[1]=0x8a001f
       (Pr=0x8a,Ty=31)
      PFL[1]=0x2
      PID[2]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[2]=0x2
      PID[3]=0x8b001f
       (Pr=0x8b,Ty=31)
      PFL[3]=0x2
    ==========
    Sort 5 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1b0013
       (Pr=0x1b,Ty=19)
      PFL[0]=0x0
    ==========
    Sort 6 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x82001f
       (Pr=0x82,Ty=31)
      PFL[0]=0x2
      PID[1]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[1]=0x4
    ==========
    Sort 7 has 3 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x101001f
       (Pr=0x101,Ty=31)
      PFL[0]=0x2
      PID[1]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[1]=0x2
      PID[2]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[2]=0x4
    ==========
    Sort 8 has 3 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[0]=0x4
      PID[1]=0x101001f
       (Pr=0x101,Ty=31)
      PFL[1]=0x2
      PID[2]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[2]=0x2
    ==========
    Sort 9 has 6 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x89001f
       (Pr=0x89,Ty=31)
      PFL[0]=0x2
      PID[1]=0x8a001f
       (Pr=0x8a,Ty=31)
      PFL[1]=0x2
      PID[2]=0x101001f
       (Pr=0x101,Ty=31)
      PFL[2]=0x2
      PID[3]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[3]=0x2
      PID[4]=0x8b001f
       (Pr=0x8b,Ty=31)
      PFL[4]=0x2
      PID[5]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[5]=0x4
    ==========
    Sort 10 has 6 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1020013
       (Pr=0x102,Ty=19)
      PFL[0]=0x4
      PID[1]=0x89001f
       (Pr=0x89,Ty=31)
      PFL[1]=0x2
      PID[2]=0x8a001f
       (Pr=0x8a,Ty=31)
      PFL[2]=0x2
      PID[3]=0x101001f
       (Pr=0x101,Ty=31)
      PFL[3]=0x2
      PID[4]=0x80001f
       (Pr=0x80,Ty=31)
      PFL[4]=0x2
      PID[5]=0x8b001f
       (Pr=0x8b,Ty=31)
      PFL[5]=0x2
    ==========
    Sort 11 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x90001f
       (Pr=0x90,Ty=31)
      PFL[0]=0x2
    ==========
    Sort 12 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x91001f
       (Pr=0x91,Ty=31)
      PFL[0]=0x2
    ==========
    Sort 13 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x92001f
       (Pr=0x92,Ty=31)
      PFL[0]=0x2
    ==========
-------------------
[5] PIMNamedPropTags
    OID: 1078186002
    Version: 2
    44 RECS,
    Type: 80
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x1001f
       (Pr=0x1,Ty=31)
      PFL[0]=0x2
    ==========
    Sort 1 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x20013
       (Pr=0x2,Ty=19)
      PFL[0]=0x0
    ==========
-------------------
[6] PIMNamedPropVals
    OID: 1078186008
    Version: 2
    344 RECS,
    Type: 81
    Size: 0
    Flags: 0x17
    1 sort orders:
    ==========
    Sort 0 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x200
      PID[0]=0x10013
       (Pr=0x1,Ty=19)
      PFL[0]=0x0
      PID[1]=0x20013
       (Pr=0x2,Ty=19)
      PFL[1]=0x0
    ==========
-------------------
[7] PIMNamedPropValsIndexed
    OID: 1078186014
    Version: 2
    221 RECS,
    Type: 81
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x10013
       (Pr=0x1,Ty=19)
      PFL[0]=0x0
      PID[1]=0x20013
       (Pr=0x2,Ty=19)
      PFL[1]=0x0
    ==========
    Sort 1 has 3 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x20013
       (Pr=0x2,Ty=19)
      PFL[0]=0x0
      PID[1]=0x30041
       (Pr=0x3,Ty=65)
      PFL[1]=0x0
      PID[2]=0x40013
       (Pr=0x4,Ty=19)
      PFL[2]=0x4
    ==========
-------------------
[8] speed.db
    OID: 1078099984
    Version: 2
    2 RECS,
    Type: 0
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x20002
       (Pr=0x2,Ty=2)
      PFL[0]=0x0
    ==========
    Sort 1 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x1200
      PID[0]=0x10000066
       (Pr=0x1000,Ty=102)
      PFL[0]=0x0
    ==========
-------------------
[9] SyncScheduler
    OID: 1078185991
    Version: 2
    2 RECS,
    Type: 0
    Size: 0
    Flags: 0x17
    2 sort orders:
    ==========
    Sort 0 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x200
      PID[0]=0x1f
       (Pr=0x0,Ty=31)
      PFL[0]=0x0
    ==========
    Sort 1 has 1 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x20040
       (Pr=0x2,Ty=64)
      PFL[0]=0x0
    ==========
-------------------
[10] Tasks Database
    OID: 1078013970
    Version: 2
    2 RECS,
    Type: 26
    Size: 0
    Flags: 0x17
    2 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]=0x20001f
       (Pr=0x20,Ty=31)
      PFL[0]=0x2
    ==========
-------------------
[11] xbase.db
    OID: 1078153217
    Version: 2
    148 RECS,
    Type: 0
    Size: 0
    Flags: 0x17
    3 sort orders:
    ==========
    Sort 0 has 3 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x40013
       (Pr=0x4,Ty=19)
      PFL[0]=0x1
      PID[1]=0x70040
       (Pr=0x7,Ty=64)
      PFL[1]=0x1
      PID[2]=0x10013
       (Pr=0x1,Ty=19)
      PFL[2]=0x0
    ==========
    Sort 1 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x10013
       (Pr=0x1,Ty=19)
      PFL[0]=0x0
      PID[1]=0x40013
       (Pr=0x4,Ty=19)
      PFL[1]=0x1
    ==========
    Sort 2 has 2 props:
    [wVersion ]=  2
    [wKeyFlags]=0x0
      PID[0]=0x40013
       (Pr=0x4,Ty=19)
      PFL[0]=0x1
      PID[1]=0x10013
原文地址:https://www.cnblogs.com/mondol/p/1693844.html