X
X
xtensp2020-06-17 23:04:54
C++ / C#
xtensp, 2020-06-17 23:04:54

How to connect to SQLite3?

I decided to connect the sqlite3.dll library to the project using explicit linking. But when trying to connect to the database, the idea fails... Studio points to ' identifier is undefined ' . I can't figure out what I'm doing wrong. help me please

typedef int (*function);
    {
        HMODULE hm = LoadLibrary(L"sqlite3.dll");

        if (NULL == hm)
        {
            cout << (" not found!\\n");
        }
        else
        {
            function SQLITE_OPEN_READONLY = (function)GetProcAddress(hm, "sqlite3_open_v2");
            function sqlite3_close = (function)GetProcAddress(hm, "sqlite3_open_v2");
            if ((NULL == SQLITE_OPEN_READONLY) || (NULL == sqlite3_close))
            {
                cout << (" doesn't export functions\\n");
            }
            else
            {   
                              
                sqlite3* sql_db = NULL;
                status = sqlite3_open_v2(TEMP_DB_PATH, &sql_db, SQLITE_OPEN_READONLY, NULL);
                   
                if (status != SQLITE_OK) 
                {
                    sqlite3_close(sql_db);
                    DeleteFile(TEXT(TEMP_DB_PATH));
                }
                 cout << "OK"<< endl;
            }
           
        }      
        FreeLibrary(hm);
        _getch();
    }    
    return 0;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2020-06-17
@saboteur_kiev

identifier is undefined

Where exactly does she point it out?
She either does not know about the specified variable, or about the specified function. They need to be identified or connected correctly.

G
galaxy, 2020-06-17
@galaxy

How about adding a header file?

J
jcmvbkbc, 2020-06-18
@jcmvbkbc

typedef int(*function);

This is not a function pointer type definition. This is a pointer to an int. A function pointer looks something like this:
typedef int (*function)(void);
status = sqlite3_open_v2(TEMP_DB_PATH, &sql_db, SQLITE_OPEN_READONLY, NULL);

It looks like a normal binding. Because sqlite3_open_v2 looks like a function name, not a pointer obtained via GetProcAddress. For it to work, the sqlite3_open_v2 function must be properly declared at compile time, and the implib sqlite3 must be linked at link time.
But what's the point of mixing such binding and LoadLibrary/GetProcAddress in the same code?
sqlite3_close(sql_db);

If sqlite3_close takes a parameter, that parameter must also be in the typedef that defines its type. For example:
typedef sqlite3;
typedef int (*fn1) (sqlite3* db);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question