import 3rd-party DLL

I know that there are many threads about DLLs already, but they all cover the case that you want to import a dll you created yourself first. I'm trying to get the sqlite3.dll working with my programm. This is my code:

#define sQliteDLL __declspec( dllimport )

int feedBack;
sQliteDLL typedef struct sqlite3 sqlite3;
sQliteDLL int sqlite3_open(const char* filename, sqlite3 **ppDb);

sqlite3 *db;
feedBack = sqlite3_open ("test.db",&db);

What I understood so far:
I need to create a prototyp of my function etc. with the dllimport-thing to tell the linker where to look for the code of those functions. After that I can use the functions as they had been declared normally in the code. When I compile this i get:

.\sQlite.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\sQlite.cpp(9) : error C2086: 'int feedBack' : redefinition
.\sQlite.cpp(4) : see declaration of 'feedBack'

I linked the lib and the def file to the project so this should be fine.
Any idea what this is about
(int) feedBack = (int) sqlite3_open() only gives me a 'type (int) unexpected'


Answer this question

import 3rd-party DLL

  • Srik Raghavan

    Those dlls drive me crazy. If I try to link them explicit this
    HINSTANCE sQliteDLL = LoadLibraryW (_T("sqlite/sqlite3.dll"));
    is working. But this
    HINSTANCE sQliteDLL;
    sQliteDLL = LoadLibraryW (_T("sqlite/sqlite3.dll"));
    isnt.
    .\sQlite.cpp(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    .\sQlite.cpp(16) : error C2040: 'sQliteDLL' : 'int' differs in levels of indirection from 'HINSTANCE'
    .\sQlite.cpp(16) : error C2440: 'initializing' : cannot convert from 'HMODULE' to 'int'
    What is the difference I just dont give the variable a value at initialization.

  • Flying B

    You can ignore that. That error pops up because you have simply defined sqlite3 as:

  • Dave555

    Oh stupid me. Ive been doing this thing all day so I now forgot to put in a function. Thank you for that. Hope to get it work now.

  • joe everett

    Oh and I dug a little bit in the sqlite sources, I dont see any dllexport there. Is implicit linking (this is what this technique is called right) possible with a precompiled dll

  • Akhila

    Do you have a function body Those errors indicate you aren't putting the code in a function body. I managed to get this code to work in a cpp file:

    #define sQliteDLL __declspec( dllimport )

    extern "C"
    {/* use C linkage because sqlite3 was compiled in C */

      sQliteDLL typedef struct sqlite3 sqlite3;
      sQliteDLL
    int sqlite3_open(const char* filename, sqlite3 **ppDb);

    }

    int main()
    {

      int feedBack;
      sqlite3 *db;
      feedBack = sqlite3_open (
    "test.db", &db);
     
    return 0;

    }

    Of course, Even if this app built and ran without error, it still leaks memory and/or DB handles (because we aren't closing the connection).



  • Iyigun

    Ok. Thx for all that help. Pretty fast response time here. I think I will look in here more often (not only to get help )

  • Agner

    sQlite.obj : warning LNK4248: unresolved typeref token (0100001A) for 'sqlite3'; image may not run

    I get this now. But if i run it and call the function it still works. Just a warning thx in advance


  • import 3rd-party DLL