WinCE自带数据库的问题
MyLar 2008-08-07 01:54:22 我最近想做一个WinCE自带的数据库的程序,用来做个人的账务管理,在网上看了好多资料了,照着做就是没有成功,请各位高手们不吝赐教。下面是我看到的一些代码。
PCEGUID CeGuid, CeGuid1;
CEOID CeOID, CeOID1;
CEDBASEINFOEX CeDBaseInfoEx;
BOOL bCre = CeMountDBVol(CeGuid, _T("\\Test.cdb"), OPEN_ALWAYS);(1)
DWORD error = ::GetLastError();(2)
HANDLE CDataBaseTestDlg::OpenDatabase(
HWND hwndNotify, // Handle to the window to which
// notification messages are posted.
PCEGUID pceguid, // Pointer to the mounted database
// volume in which the database that
// will be opened resides.
CEOID CeOid) // Object identifier of the database
// to be opened.
{
int index;
DWORD dwError; // Return value from GetLastError
HANDLE hDataBase; // Open handle to the address database
CENOTIFYREQUEST *pRequest; // CENOTIFYREQUEST structure
CEDBASEINFO CEDBInfo; // Structure containing the database data
TCHAR szError[100]; // String to use with error messages
// Allocate memory for pRequest.
pRequest =(CENOTIFYREQUEST *) LocalAlloc(LPTR, sizeof(CENOTIFYREQUEST));
pRequest->dwSize = sizeof(CENOTIFYREQUEST);
pRequest->hwnd = hwndNotify;
pRequest->hHeap = NULL; // Let system allocate memory properly.
pRequest->dwFlags = 0; // Notifications are handled as they were in Windows CE version 1.0.
hDataBase = CeOpenDatabaseEx(
pceguid, // Pointer to the mounted volume
&CeOid, // Location for the database identifier
TEXT("\\Point.cdb"), // Database name
0, // Sort order; 0 indicates to ignore
CEDB_AUTOINCREMENT, // Automatically increase seek pointer
pRequest); // Pointer to a CENOTIFYREQUEST
// structure
if(hDataBase == INVALID_HANDLE_VALUE)
{
dwError = GetLastError();
if(dwError == ERROR_NOT_ENOUGH_MEMORY)
{
wsprintf(szError, TEXT("Not enough memory"));
}
else
{
// Possibility of non-existent database; create it.
// Initialize structure CEDBInfo
memset(&CEDBInfo, 0, sizeof(CEDBInfo));
// Create the database with the following specified flags.
// Create the database as uncompressed.
// You can use CeSetDataBaseInfoEx to compress the database.
CEDBInfo.dwFlags =
CEDB_VALIDNAME // szDbaseName is valid
| CEDB_VALIDTYPE // dwDbaseType is valid
| CEDB_VALIDDBFLAGS // HIWORD of dwFlag is valid
| CEDB_VALIDSORTSPEC // rgSortSpecs is valid
| CEDB_NOCOMPRESS; // The database is not compressed.
// Assign the database name as Test.cdb.
wcscpy(CEDBInfo.szDbaseName, TEXT("MyDB"));
// Assign the database type.
CEDBInfo.dwDbaseType = 0;
// Set the number of active sort orders to 4.
// This is the maximum number allowed.
CEDBInfo.wNumSortOrder = 4;
// Initialize the array of sort-order descriptions.
for(index = 0; index < CEDBInfo.wNumSortOrder; ++index)
{
// Sort in descending order.
CEDBInfo.rgSortSpecs[index].dwFlags = CEDB_SORT_DESCENDING;
// Assign the identifier of the properties by which to sort.
// CEDBInfo.rgSortSpecs[index].propid = ...;
}
// Create database "Test.cdb".
CeOid = CeCreateDatabaseEx(pceguid, &CEDBInfo);
if(CeOid == NULL)
{
wsprintf(szError,
TEXT("ERROR:CeCreateDatabaseEx failed(%ld)"),
GetLastError());
}
else // Succeeded in creating the database; open it.
{
hDataBase = CeOpenDatabaseEx(pceguid, &CeOid,
TEXT("MyDB"), 0, 0, pRequest);
}
}
}
(1)如果从台式机上创建一个文件,然后将后缀名改成cdb,那么本条语句返回1,否则总是返回0
(2)如果(1)返回1,那么这条就返回183,如果(1)返回0,这条就返回87.
请各位高手帮忙看看啊,多谢了