開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Eclipse
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
sqlite3
問題(Question):
請問各位前輩使用C++ Compile成DLL的方式(裡面有使用sqlite)要給C call,是否正確?
謝謝~
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o sqlite3.o sqlite3.c
g++ -DBUILD_DLL -O0 -g3 -Wall -c -fmessage-length=0 -o test_Cpp2.o test_Cpp2.cpp
g++ -shared -otest.dll test_Cpp2.o sqlite3.o
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
test_Cpp2.cpp 內容
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <windows.h>
extern "C" __declspec( dllexport ) double __stdcall add2(char *num)
{
int rc=0;
sqlite3_stmt * stmt;
sqlite3 *db ;
/* 開啟 database 檔 */
sqlite3_initialize( );
rc = sqlite3_open("test.db", &db);
if ( rc != SQLITE_OK)
{
return 0;
}
const char *sql = "SELECT * FROM TABLE1 where col1=?";
sqlite3_prepare_v2(db, sql, strlen (sql) + 1, & stmt, NULL);
sqlite3_bind_text(stmt, 1, num, -1, SQLITE_TRANSIENT);
return 0;
while (1) {
int s;
s = sqlite3_step(stmt);
if (s == SQLITE_ROW) {
double text2 = sqlite3_column_double(stmt, 1);
return text2;
}
else if (s == SQLITE_DONE) {
break;
}
else {
return 0;
}
}
}
補充說明(Supplement):