天天看點

wince6.0移植SQLite生成LIB、DLL

1. 去SQLite官網http://www.sqlite.org/download.htm下載下傳最新的source code

2.  在VS2005下建立一個Win32智能裝置項目,選擇相應的SDK,并選擇應用程式類型為DLL(空項目)

3.  将sqlite-amalgamation-201401042000.zip解壓後的sqlite3.c、sqlite3.h檔案拷貝到工程目錄下并添加至工程目錄

4.在預進行中增SQLITE_ENABLE_RTREE和SQLITE_ENABLE_COLUMN_METADATA宏定義

wince6.0移植SQLite生成LIB、DLL

5.将源檔案sqlite3.c中 14660行localtime_s替換成_localtime64_s

6. 在SQLite官網上下載下傳sqlite-dll-win32-x86-XXXXXX.zip檔案,解壓後将目錄下的sqlite3.def檔案拷貝到DLL工程目錄,在項目屬性--連結器--輸入--子產品定義檔案中添加sqlite3.def

7.編譯相應目錄下生成lib、dll檔案

使用測試程式測試

1.目前項目下建立立項目SQLite_test,同時設定新項目依賴于SQLite

wince6.0移植SQLite生成LIB、DLL

2.SQLite_test.cpp檔案中添加如下代碼:

// SQLite_test.cpp : 定義應用程式的入口點。

//

#include "stdafx.h"

#include "SQLite_test.h"

#include <windows.h>

#include <commctrl.h>

#include "sqlite3.h"

// sqlite3的回調函數

int SQLiteQueryResultCallBack( void * para, int n_column, char ** column_value, char ** column_name )

{

printf( "******************************\n" );

printf("includ %d id\n", n_column );

for(int i = 0 ; i < n_column; i ++ )

{

printf( "name:%s value:%s\n", column_name[i], column_value[i] );

}

printf( "******************************\n" );

Sleep(5000);

return 0;

}

int WINAPI WinMain(HINSTANCE hInstance,

                   HINSTANCE hPrevInstance,

                   LPTSTR    lpCmdLine,

                   int       nCmdShow)

{

#if 1

sqlite3 * db = NULL; //聲明sqlite關鍵結構指針

int result;

// 打開或建立資料庫

result = sqlite3_open("mydb.db", &db );

if( result != SQLITE_OK )

{

//資料庫打開失敗

return -1;

}

char * errmsg = NULL;

// 資料庫操作代碼

// 建立一個測試表,表名叫 MyTable,有2個字段: ID 和 name。其中ID是一個自動增加的類型,以後insert時可以不去指定這個字段,它會自己從0開始增加

result = sqlite3_exec( db, "create table MyTable( ID integer primary key autoincrement, name nvarchar(32) )", NULL, NULL, &errmsg );

if(result != SQLITE_OK )

{

printf("建立表失敗,錯誤碼:%d,錯誤原因:%s\n", result, errmsg );

}

// 插入記錄

result = sqlite3_exec( db, "insert into MyTable( name ) values ( 'zhangshan' )", 0, 0, &errmsg );

if(result != SQLITE_OK )

{

printf("插入記錄失敗,錯誤碼:%d,錯誤原因:%s\n", result, errmsg );

}

// 插入記錄

result = sqlite3_exec( db, "insert into MyTable( name ) values ( 'lisi' )", 0, 0, &errmsg );

if(result != SQLITE_OK )

{

printf("插入記錄失敗,錯誤碼:%d,錯誤原因:%s\n", result, errmsg );

}

// 開始查詢資料庫

result = sqlite3_exec( db, "select * from MyTable", SQLiteQueryResultCallBack, NULL, &errmsg );

// 關閉資料庫

sqlite3_close( db );

#endif

return 0;

}

3.編譯運作,模拟器出現如下錯誤

wince6.0移植SQLite生成LIB、DLL

 4.此問題解決方法如下:

将dll項目SQLite的屬性頁中調試中的遠端可執行檔案、部署中的遠端目錄設定和SQLite_test(執行檔案)項目中對應項一樣

具體可以參照 使用vs2005進行(wince)DLL源碼調試 :

http://blog.chinaunix.net/uid-24866372-id-2129467.html

wince6.0移植SQLite生成LIB、DLL

5.設定完成之後編譯即可。

其它參照文章:

WINCE下使用SQLite資料庫

http://blog.csdn.net/firehood_/article/details/8129612