首页 新闻 会员 周边 捐助

wince开发中,调用sqlite数据库不成功,怎么办?

0
悬赏园豆:100 [已解决问题] 解决于 2012-09-22 17:21

你好!我用的vs2005软件做wince应用开发。工程是用c++编写的,项目模版选的是“win32智能设备” 。sqlite是用c写的,sqlite库包含:main.c,sqlite.c,sqlite.h,还有一个cabledetection.db数据库。我将它们都添加到 工程项目里。  运行后,无法调数据库里的表格。提示只有一个警告"_localtime64_s"undefined; assuming extern returning int

此工程功能是:调用sqlite库表格的坐标值,画直线。相关代码:

#include <windows.h>
#include "OkLine.h"
#include "sqlite3.h"
const TCHAR szAppName[] = TEXT("PenTrac");
HINSTANCE hInst;

const struct decodeUINT MainMessages[] = {     //消息表格(结构体)

    WM_LBUTTONDOWN,DoMouseMain,
    WM_MOUSEMOVE,DoMouseMain,
    WM_DESTROY,DoDestroyMain,
};
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)
{
    MSG msg;
    int rc = 0;
    HWND hwndMain;
    hwndMain = InitInstance(hInstance,lpCmdLine,nCmdShow);
    if(hwndMain == 0)
    {
        return 0;
    }
    while (GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);  //将键盘消息转换为字符消息
        DispatchMessage(&msg);   //通知windows将消息分发到该应用程序的合适的窗口
    }
    return TermInstance(hInstance,msg.wParam);
}
HWND InitInstance(HINSTANCE hInstance,LPWSTR lpCmdLine,int nCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;

#if defined(WIN32_PLATFORM_PSPC)||defined(WIN32_PLATFORM_WFSP)
    hWnd = FindWindow(szAppName,NULL);
    if(hWnd)
    {
        SetForegroundWindow((HWND)(((DWORD)hWnd)|0x01));
        return 0;
    }
#endif
    hInst = hInstance;
    wc.style = 0;
    wc.lpfnWndProc = MainWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szAppName;

    if(RegisterClass(&wc) == 0)
        return 0;
    hWnd = CreateWindowEx(WS_EX_NODRAG,szAppName,TEXT("PenTrac"),WS_VISIBLE|WS_CAPTION|WS_SYSMENU,
                          CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,NULL,NULL);
    if(!IsWindow(hWnd))
        return 0;
    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);
    return hWnd;
}
int TermInstance(HINSTANCE hInstance,int nDefRC)    //终止进程
{

    return nDefRC;
}
LRESULT CALLBACK MainWndProc(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam)
{
    INT i;
    for(i = 0;i<dim(MainMessages);i++)
    {
        if(wMsg == MainMessages[i].Code)
            return (*MainMessages[i].Fun)(hWnd,wMsg,wParam,lParam);
    }
    return DefWindowProc(hWnd,wMsg,wParam,lParam);
}
LRESULT DoMouseMain(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam)
{

    HDC hdc;
    hdc = GetDC(hWnd);

    sqlite3 *db;
    char *ErrMsg = 0;
    int ret;
    char **Result;
    char *sql;
    int nrow = 0, ncolumn = 0;
    int i; 
    ret = sqlite3_open("cabledetection.db", &db);
    if (ret)
    {
        fprintf(stderr, "can not open database:%s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(1);
    }
    else
    {
        printf("You have open a sqlite3 database named cabledetection.db sucessful!\n");
    }
                                                                                      //电缆路径表
    sql="CREATE TABLE TB_CablePath(Id INT NOT NULL,CableUniqueId UNIQUEIDENTIFIER PRIMARY KEY NOT NULL,PostionX float NOT NULL,PostionY float NOT NULL,PostionZ float NOT NULL,[Index] [int],Remark NVARCHAR(256));";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);

    sql = "INSERT INTO TB_CablePath VALUES(20, 'ffff', 23.0, 45.0, 30.0, 100, '无');";//电缆路径插入
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);
    sql = "INSERT INTO TB_CablePath VALUES(21, 'vvvv', 133.0, 65.0, 33.0, 110, '无');";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);
    sql = "INSERT INTO TB_CablePath VALUES(22, 'gggg', 53.0, 250.0, 13.0, 10, '无');";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);
    sql = "INSERT INTO TB_CablePath VALUES(23, 'hhhh', 280.0, 280.0, 280.0, 12, '无');";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);
    sql = "INSERT INTO TB_CablePath VALUES(24, 'mmmm', 300.0, 8.0,  110.0, 18, '无');";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);
    sql = "INSERT INTO TB_CablePath VALUES(25, 'kkkk', 318.0, 240.0,  12.0, 17, '无');";
    sqlite3_exec(db, sql, 0, 0, &ErrMsg);



    sql = "SELECT * FROM TB_CablePath";                                               //查询电缆路径数据
    sqlite3_get_table(db, sql, &Result, &nrow, &ncolumn, &ErrMsg);    //Result是以数组形式存放锁查询的数据,首先是表名,再是数据,nrow为行,ncolumn为列,查询无结果时返回0
    for(i=0; i<(nrow+1)*ncolumn; i++)
    {
        printf("Result[%d] = %s\n", i, Result[i]);
        if((i+1)%ncolumn == 0 && i != 0)
        {
            printf("\n");
        }
    }                              
    MoveToEx(hdc,100,80,NULL);
    LineTo(hdc,250,10);
    MoveToEx(hdc,100,80,NULL);
    LineTo(hdc,420,100);
    MoveToEx(hdc,100,80,NULL);
    LineTo(hdc,150,300);

    sqlite3_free_table(Result);        //释放掉Result的内存空间
    sqlite3_close(db);                   //关闭数据库
    GetCurrentPositionEx(hdc,NULL);
    ReleaseDC(hWnd,hdc);


    return 0;

}
LRESULT DoDestroyMain(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam)
{
    PostQuitMessage(0);
    return 0;
}

请高手指点:如何才能调用坐标值成功。(不用.lib  .dll  .h那种形式调用库)。谢谢

anlexiaopang的主页 anlexiaopang | 初学一级 | 园豆:114
提问于:2012-09-21 11:56
< >
分享
最佳答案
0
收获园豆:100
2012 | 高人七级 |园豆:21645 | 2012-09-21 12:18

谢谢,我是wince初学者,我之前也在网上下载了sqlite3的源码,并成功编译出sqlite3.dll与sqlite3.lib。并把“sqlte3.h、sqlite3.dll与sqlite3.lib”添加到工程目录下,实现了网上的一个试验箱的例子。

但是,我有个疑问:

"工程里调用数据库时。都要先将’sqlte3.h、sqlite3.dll与sqlite3.lib‘添加到工程目录下

然后,在.cpp文件里编写数据库;

还是不加入它们,直接将自己编好的.sqlite.c、sqlite.h、main.c加入工程里“。请指教。

anlexiaopang | 园豆:114 (初学一级) | 2012-09-21 14:38

@anlexiaopang: sqlite3的文件很多的,最好还是用一个库,防止自己的编译选项和库的在一起,麻烦

项目引用库,你用的是一种方法,还可以在代码中使用 #pragma comment(lib, "../lib/sqlite3.lib") 的形式

2012 | 园豆:21645 (高人七级) | 2012-09-22 10:37

@2012: 对,我刚改用库   #pragma comment(lib,"../lib/sqlite3.lib")的形式。  出现了很多链接错误:如“无法解析的外部符号sqlite3_get_table,该符号在函数在****在被引用”,我也查了很多网上资料,但没解决,请指点。

anlexiaopang | 园豆:114 (初学一级) | 2012-09-22 17:18

@anlexiaopang: sqlite3.lib一定要放对位置,"../lib/sqlite3.lib"表示当前上一目录的lib子目录下放sqlite3.lib

2012 | 园豆:21645 (高人七级) | 2012-09-24 08:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册