A property database can be deleted by calling CeDeleteDatabaseEx. This function requires the CEGUID of the mounted database volume and the object identifier of the database to delete. The easiest way to obtain the object identifier is to call CeOpenDatabaseEx passing in the name of the database, and the object identifier is returned in ceOidDB, as illustrated in Listing 4.6. Listing 4.6 Deletes a databasevoid Listing4_6() { CEGUID ceObjStore; CEOID ceOidDB = 0; HANDLE hDB; CREATE_SYSTEMGUID(&ceObjStore); hDB = CeOpenDatabaseEx(&ceObjStore, &ceOidDB, _T("Company"), 0,0, NULL); if(hDB == INVALID_HANDLE_VALUE) cout _T("Could not open database") endl; else { CloseHandle(hDB); if(CeDeleteDatabaseEx(&ceObjStore, ceOidDB)) cout _T("Database deleted") endl; else cout _T("Database not deleted") endl; } } Remember, it is important to initialize ceOidDB to zero, otherwise CeOpenDatabaseEx will attempt to use the value as a valid database object identifier. You cannot delete a database that is open, so ensure that you close the database before attempting to delete it.
|