Hello, Teg,

On Fri, Feb 26, 2016 at 11:41 AM, Teg <Teg at djii.com> wrote:
> Hello Igor,
>
> I use Sqlite through a DLL interface. I mean I have another DLL that
> includes Sqlite static linked inside it. All opening, closing and
> access to Sqlite takes place inside the context of the DLL. The
> application never makes Sqlite calls directly. Instead it uses higher
> level functions inside the DLL which talk to the Database through
> Sqlite.

My structure is just like yours:

DLL1

class __declspec(dllexport) Database
{
public:
    Database();
    virtual ~Database();
    virtual int Connect(const char *dbName);
};

DLL2:

class __declspec(dllexport) SQLiteDatabase : public Database
{
public:
    SQLiteDatabase();
    virtual ~SQLiteDatabase();
    virtual int Connect(const char *dbName);
private:
    sqlite3 *m_db;
};

DLL3:

extern "C" __declspec(dllexport) Database *ConnectToDB(Database *db)
{
    db = new SQLiteDatabase;
    return db;
}

main application:

class A
{
public:
    A(Database *db)
    {
        m_db = NULL;
       HINSTANCE hInst = LoadLibrary( TEXT( "dialogs.dll" ) );
       MYFUNC func = (MYFUNC) GetProcAddress( hInst, "DatabaseProfile" );
       m_db = func( db );
    }
    ~A()
    {
    }
    Database *GetDatabase()
    {
        return m_db;
    }
    private: Database *m_db;
};

int _tmain(int argc, _TCHAR* argv[])
{
    Database *db = NULL, *m_db;
    A *a = new A( db );
    m_db = a->GetDatabase();
    delete m_db;
    delete a;
    return 0;
}

Full code is in here:
http://stackoverflow.com/questions/35345258/crash-when-disconnecting-from-sqlite-database

Is CL suggestion makes sense?

Thank you.

> I've not attempted to do what you're doing exactly. I don't like
> sharing memory across the DLL boundary because I mostly use static
> linkage. It causes issues. I'll use allocated memory as handles to a
> class inside the DLL but to the caller it's just a black box. The
> caller doesn't know what the handle contains (like a file handle).
>
>
> Thursday, February 25, 2016, 10:31:49 AM, you wrote:
>
> IK>  Hi,
> IK> I'm trying to design/make a program where I will use SQLite from the DLL.
>
> IK> What I mean is I will establish a connection inside a DLL but disconnect 
> from
> IK> the database in my main application.
>
> IK> It turns out that doing so I am getting the crash when I try to 
> disconnect from
> IK> the database file.
>
> IK> Connecting to the DB and issuing the query works OK and the data is 
> retrieved.
>
> IK> I put up some small demo if you need a code to look at.
>
> IK> Thank you.
> IK> _______________________________________________
> IK> sqlite-users mailing list
> IK> sqlite-users at mailinglists.sqlite.org
> IK> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
>
> --
>  Teg                            mailto:Teg at djii.com
>

Reply via email to