CeGetDatabaseProps


Now that CEDB is deprecated in Windows Mobile 5.0, you may be running across one gotcha in the EDB API, namely, CeGetDatabaseProps().  From reading the docs, you might think that you can call CeGetDatbaseProps like this:


       CeGetDatabaseProps(m_hDb, &wNumProps, NULL, NULL))
 
       CEPROPID *rgPropID = new CEPROPID[wNumProps+1];
       CEPROPSPEC* prgProps = new CEPROPSPEC[wNumProps+1];


       CeGetDatabaseProps(m_hDb, &wNumProps, rgPropID, prgProps);


       for (int i=0; i<wNumProps; i++)
       {
           // Do something
       }


 


But, actually, you need to set up the CEPROPSPECs first:


       CeGetDatabaseProps(m_hDb, &wNumProps, NULL, NULL))
 
       CEPROPID *rgPropID = new CEPROPID[wNumProps+1];
       CEPROPSPEC* prgProps = new CEPROPSPEC[wNumProps+1];


       for (int i=0; i< wNumProps; i++)
       {


           prgProps[i].wVersion = CEPROPSPEC_VERSION;


           prgProps[i].pwszPropName = new WCHAR[ CEDB_MAXDBASENAMELEN  ];


           prgProps[i].cchPropName=  CEDB_MAXDBASENAMELEN; // We need to specify the length of buffer we are passing in for pwszPropName


       }


       CeGetDatabaseProps(m_hDb, &wNumProps, rgPropID, prgProps);


       for (int i=0; i<wNumProps; i++)
       {
           // Do something
       }



Comments (1)

  1. kenny says:

    Well, you ALMOST got it right, instead of allocating the CEPROPID array and passing it in, what you probably wanted to do was pass in a null for that parameter:

    CeGetDatabaseProps(m_hDb, &wNumProps, NULL, prgProps);

    This results in the entire list of elements returns as I think you intended, if you specify the list of items it returns only those.  Also, the +1 is useless data in the array since it won’t by used.